Integrity and foreign keys in SQL Server

Source: Internet
Author: User
Tags domain
Server

Integrity is the consistency and validity of data in a database. The usual statements are entity (ROW) integrity, domain (column) integrity, and referential integrity (refer to SQL Server).

Entity integrity defines all rows in the table that are uniquely identified, typically with primary keys, unique indexes unique keywords, and identity attributes such as our ID number to uniquely identify a person.


Domain integrity usually refers to the validity of the data, limiting the data type, default value, rules, constraints, whether it can be null, and domain integrity to ensure that no invalid values are entered.

Referential integrity maintains the validity and completeness of data between tables, usually by establishing a foreign key to contact another table's primary key, for example, there are two tables in the Library management system, one is the staff table (Pid,pname ...) , to record the information of the borrower, in order to ensure the uniqueness of the personnel, can be in the field of PID primary key, unique index. The other is the loan schedule (... pid ...).), in the loan list to build a foreign key to two of the table of the PID link, to ensure that the people in the loan table in the range, in addition, if someone in the lending table has not yet recorded the books, then he can not be deleted in the people table. You can also use triggers to maintain referential integrity.



Related Article

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.