To prevent random filling:
One, check constraints.
Check the data according to a certain rule.
Action: In the table design interface, right-click the appropriate column, select Check Constraint in the popup dialog box, set the name and expression of the constraint.
Code implementation:
CREATE TABLE Car
(
code int Check (CODE>0)
)
Second, foreign KEY constraints. The main table, from the table.
The primary table is used to constrain the from table. The foreign key should be built from the table.
Use the primary key of the main table to constrain the foreign key from the table.
The foreign key column from the table cannot be arbitrarily filled, it can only fill in the data that exists in the primary key of the main table.
once the foreign key relationship is established, the foreign key from the table cannot be filled out, and the primary key column in the main table can not be deleted randomly.
Settings for cascading deletions--sorting
Action: First build the main table, in the table from the design interface, right-click-"Relationship", in the Popup dialog box select "Add", in the right attribute list "table and column Specification"
The second method is to create a new database diagram on the corresponding database diagram.
Code implementation
CREATE TABLE Car
(
Code Varvhar (primary key),
Brand varchar (reference brand) (Brand_Code)
)
The main table is the brand table
Three, type.
Create a data type defined by all columns of a table
Character data: Char;varchar
Date Time Data: Datetime;smalldatetime
Numeric data: Bigint;int;smallint;tinyint
A decimal (A, a, a, A, b) represents the number of digits that contain decimals and decimal points, and a number of decimal places. That is, the number of integer digits is a-b-1 (one decimal point)
SQL database constraint behavior---Prevent data scrambling (that is, data normalization)