SQL Constraints |
SQL Sample Code - SQL Constraints. |
Constraints are used to restrict the type of data that goes into a table.
There are a number of different types of ‘Constraints’;
| Constraint | Description |
| NOT NULL | Enforces a column not to allow NULL values. (Not allowed to leave empty) |
| UNIQUE | Ensures all values in a column are different. |
| PRIMARY KEY | Primary key columns must contain unique values and a primary key column cannot contain NULL values. Only one column in a table can be a Primary Key |
| FOREIGN KEY | Used to ensure referential integrity of the data. |
| CHECK | Only allows values to be inserted that satisfy a defined criteria. |
| DEFAULT | Defines a default value for a column. |
Go to the related Constraint to learn more and see examples.
The constraints above can be specified:
To learn more about CREATE TABLE and ALTER TABLE go to the relevant section.
Related SQL Sample Code:
|
|