What is a constraint? sql code example

Example 1: what are the constraints in sql

NOT NULL 	 # Ensures a column cannot have a NULL value
UNIQUE 		 # Ensures all values in a column are unique
PRIMARY KEY  # Identifies a record in a table, is NOT NULL & UNIQUE
FOREIGN KEY  # References a unique record from another table
CHECK		 # Ensures all column values satisfy a condition
DEFAULT		 # Set a default value for a column if none is entered
INDEX		 # Quick way of retrieving records from database

Example 2: constraint sql

create table etc(
  numeric (4) anything constraint Gives_name_to_a_restriction primary key);

Tags:

Sql Example