DDL COMMANDS
DDL COMMANDS
DDL COMMANDS
The checks or conditions applied on one or more columns of a table are known as constraints .
Unique Constraint : This constraint ensure that all the data of the column should be unique. It
allows null values.
Primary key Constraint : This constraints is used to uniquely identify data. It does not accept null
values.
Default Constraint : This constraint is used to set a default values in case no value is provided by
user for a column.
Check Constraint: This constraint is used to set a limit for a column. for ex- no data should be
inserted less than 20 in age column.
Foreign key Constraint : it is a non –key attribute of one table derived from primary key from other
table.
Not Null : Ensures that a column cannot have NULL value.
For Ex:
mysql> create table student (
Roll INT(4) PRIMARY KEY,
Name CHAR(20) NOT NULL,
Age INT(2) CHECK (Age>5),
Class CHAR(3) Default ‘I’,
City CHAR(10) Not Null
);
Creation of a Table (Table level constraints Setting )
Renaming a column:
ALTER TABLE <table_name> CHANGE [COLUMN] <old-column-name> <new-column-name>
column_definition;
Removing a column:
ALTER TABLE <table-name> DROP <column-name>;
For example,
ALTER TABLE student DROP Mobile;