SQL Constraints
Rules for data.
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
Constraints can be specified when the table is created with the CREATE TABLE statement, or after the table is created with the ALTER TABLE statement.
Common Constraints
NOT NULL- Ensures that a column cannot have a NULL valueUNIQUE- Ensures that all values in a column are differentPRIMARY KEY- A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a tableFOREIGN KEY- Uniquely identifies a row/record in another tableCHECK- Ensures that all values in a column satisfy a specific conditionDEFAULT- Sets a default value for a column when no value is specifiedCREATE INDEX- Used to create and retrieve data from the database very quickly