expression integrity constraints in SQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.