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