There are several constraints:
Not null: the content used to control fields must NOT be NULL ).
UNIQUE: The control field content cannot be repeated. A table can have multiple Unique constraints.
Primary key: it is also used to control the content of fields that cannot be repeated, but it can only appear in one table.
Foreign key: the foreign key constraint is used to prevent the action of damaging the connection between tables. The foreign key constraint can also prevent illegal data insertion into the foreign key column, because it must be one of the values in the table to which it points.
CHECK: used to control the value range of a field.
DEFAULT: set the DEFAULT value of the new record.
1. not null: the content used to control the field must not be NULL ).
Usage: Create table MyTable
(
Id varchar (32) not null,
Name varchar (32)
)
2. Unique: the control field content cannot be repeated. A table can have multiple Unique constraints.
NEW:
Add the Unique syntax supported by SQL Server, Orcale, and MS Access:
Create table MyTable
(
Id varchar (32) not null unique,
Name varchar (32)
)
Add the Unique syntax supported by SQL Server and My SQL: you can add several fields as constraints at the same time, such as: unique (id, name)
Create table MyTable
(
Id varchar (32) not null,
Name varchar (32 ),
Unique (id ,.....)
)
Add the Unique syntax supported by SQL Server, Orcale, MS Access, and My SQL:
Create table MyTable
(
Id varchar (32) not null,
Name varchar (32 ),
Constraint uniqueName unique (UniqueColumn ,.....)
)
Delete:
Delete the Unique constraint syntax in SQL Server, Oracle, and MS Access: drop constraint UniqueName;
Delete Unique constraint syntax in My SQL: drop index UniqueName;
Modify:
Alter table EPlatform
Add constraint Unique_EPlatform
Unique ([UserId], [Platform]);
3. Primary Key: the content of the control field cannot be repeated, but only one table can appear.
Add the Primary Key syntax supported by SQL Server, Orcale, and MS Access:
Create table myTB1
(
Id nvarchar (32) not null primary key,
Name nvarchar (32)
)
Supported in SQL Server and My SQL