SQL Server organizes data with tables

Source: Internet
Author: User

I. PRIMARY KEY

Primary key as a unique identifier in the table that identifies this column does not allow duplicate data
If two or more columns are combined to uniquely identify each row in the table, the primary key is called the composite primary key

The principle of selecting a primary key
Minimum sex
Try selecting a single key as the primary key
Stability
Try selecting a column with fewer values to update as the primary key
Two. Default value

Set the column default value if this column must be allowed to be empty, otherwise the set default value is invalid
If this column is not entered when inserting data or changing data, it is bound by default values

Three: Identity column

Set the identity column you want to set as the primary key, ensure that the column has a data type of int, and then change the identity specification for this column to Yes, the identity seed represents the beginning of several, the identity increment represents each

Four: Create a primary foreign key

Foreign key table Brahma key table

Five: Considerations for the primary key table month foreign key table
1. You cannot add records to a child table when there are no corresponding records in the primary table
No school numbers that do not exist in the Student information table can be found in the score table
2. You cannot change the values in the primary table and cause the records in the child table to be orphaned
Change the number of students in the Student information table, and the student's score list should be changed as well.
3. The child table has a record corresponding to the primary table, and the row cannot be deleted from the primary table
You can't delete a student who has a score.
4. Delete the primary table before deleting the child table
Delete the student's information form after deleting the student's score form first

SQL Server organizes data with tables

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.