首页 > 数据库技术 > 详细

数据库约束知多少

时间:2016-03-11 02:05:33      阅读:287      评论:0      收藏:0      [点我收藏+]

一、数据库约束知多少

非空 、唯一 、主键? 、外键? 、检查约束

二、各约束具体含义

Not Null, which prevents a value from being null

In the EMPLOYEES table, the column LAST_NAME has the NOT NULL constraint, which enforces the business rule that every employee must have a last name.

?Unique, which prevents multiple rows from having the same value in the same column or combination of columns, but allows some values to be null

In the EMPLOYEES table, the column EMAIL has the UNIQUE constraint, which enforces the business rule that an employee can have no email address, but cannot have the same email address as another employee.

?Primary Key, which is a combination of NOT NULL and UNIQUE

In the EMPLOYEES table, the column EMPLOYEE_ID has the PRIMARY KEY constraint, which enforces the business rule that every employee must have a unique employee identification number.

?Foreign Key, which requires values in one table to match values in another table

In the EMPLOYEES table, the column JOB_ID has a FOREIGN KEY constraint that references the JOBS table, which enforces the business rule that an employee cannot have a JOB_ID that is not in the JOBS table.

?Check, which requires that a value satisfy a specified condition

The EMPLOYEES table does not have CHECK constraints. However, suppose that EMPLOYEES needs a new column, EMPLOYEE_AGE, and that every employee must be at least 18. The constraint CHECK (EMPLOYEE_AGE >= 18) enforces the business rule.

Tip:
Use check constraints only when other constraint types cannot provide the necessary checking.
?REF, which further describes the relationship between the column and the object that it references
For information about REF constraints, see Oracle Database Concepts.

数据库约束知多少

原文:http://gaojingsong.iteye.com/blog/2282034

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!