mySQL constraints

Below are the some common constraints on column:
  • NOT NULL - Ensures that a column cannot have a NULL value
  • UNIQUE - Ensures that all values in a column are different
  • PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
  • FOREIGN KEY - Uniquely identifies a row/record in another table
  • CHECK - Ensures that all values in a column satisfies a specific condition
  • DEFAULT - Sets a default value for a column when no value is specified
  • INDEX - Use to create and retrieve data from the database very quickly

CREATE TABLE Mov1 (
  ID int NOT NULL UNIQUE,
  MovName varchar(255) NOT NULL,
  Genere varchar(255) DEFAULT 'Action'
  CHECK (MovName!=NULL)
  PRIMARY KEY (ID)
);

Comments