expression integrity constraints in SQL
SQL constraint is divided into entity integrity, referential integrity, user-defined integrity, delete constraint
Entity Integrity 1. Define primary keys Create table table names when building a table ( sno int identity ( sname), nvarchar (), --set Primary key Primary key (Sno) ) 2. Add primary Key alter table table name add constraint pk_ table name _sno primary key (ID) Referential integrity 1. Define foreign keys create table table names when building a table ( sno int identity ( primary key, ) cno int not null, Foreign key (CNO) References table Name 2 (CNO) on delete cascade --Cascade Delete on update cascade --Cascade Update -- on delete on action Delete control ) 2. Add foreign key alter table table name add constraint fk_ Table Name _ 2 foreign key (CID) references table Name 2 (CID) User-defined integrity 1. Non-null constraint alter table table name alter column name varchar (20) not null 2. Unique constraint alter table table name add constraint uq_ Table Name _ Column name unique (column) 3. Check Constraint alter table table name add constraint ck_ Table Name _ Column name check (age>5) 4. Default Constraints alter table table name add constraint df_ table name _ Column name default (' Man ') for&nBsp;gender Delete constraint --delete constraint alter table table name drop Constraint df_ Table Name _ column
<LI> entity integrity: Also known as row integrity, requires that no identical rows exist in the table, and that each row has a non-empty and duplicate primary key value. <li> referential integrity: Also known as referential integrity, refers to the rules between tables, which are used for two or more tables with associations, by using the relationship between the primary key and the foreign key (or unique key) to make the key values in the table consistent across related tables. <LI> user-defined integrity: The constraint of a pointer to a specific relational database that reflects the semantic requirements that the data involved in a particular application must meet.
<li> referential integrity: Also referred to as referential integrity, refers to the rules between tables, which are used for two or more tables with associations, by using the relationship between the primary key and the foreign key (or unique key) to make the key values in the table consistent in the related table
expression integrity constraints in SQL