About The Author

This is a sample info about the author. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sed felis.

Get The Latest News

Sign up to receive latest news

Friday 26 August 2011

MySQL Alter Table Add Column Command

Alter Table command is used for modifying the structure of the table. Means to add the new column, drop the column etc.

ADD COLUMN:
Syntax:
ALTER TABLE table_name ADD COLUMN column_name column-definition [ FIRST | AFTER col_name ]
Note: We can use both ADD COLUMN or ADD for adding the column.

Example 1:
ALTER TABLE student ADD COLUMN st_phone varchar(12) NOT NULL, st_gender varchar(5) NOT NULL;

Example 3:
ALTER TABLE student ADD COLUMN st_phone varchar(12) NOT NULL AFTER st_mobile,ADD COLUMN st_gender varchar(5) NOT NULL AFTER st_name,ADD COLUMN st_id int FIRST;

Example 4:
ALTER TABLE student ADD (st_phone varchar(100), st_email varchar(200),st_address varchar(200));

Example 5:
ALTER TABLE student ADD COLUMN st_phone varchar(12) DEFAULT NULL;

Example 6:
ALTER TABLE student ADD COLUMN st_id int NOT NULL AUTO_INCREMENT PRIMARY KEY;

0 comments:

Post a Comment