0% found this document useful (0 votes)
5 views1 page

Alter Table

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Alter Table

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Alter Table:

ALTER TABLE - ADD Column:

To add a colu mn in a table, use the following syntax:

Syntax:

ALTER TABLE Customers ADD Email varchar(255);

ALTER TABLE - RENAME COLUMN:

ALTER TABLE Persons ALTER COLUMN DateOfBirth year;

Syntax:

ALTER TABLE table_ name RENAME COLUMN old_name to new_name;

ALTER TABLE - ALTER/MODIFY DATATYPE:

To change the data type of a column in a table, use the following syntax:

ALTER TABLE table_name MODIFY COLUMN column_name datatype;

change the column position:

You can change the column position of MySQL table without losing data with the help of ALTER
TABLE command. The syntax is as follows –

ALTER TABLE yourTableName MODIFY yourColumnName1 data type AFTER yourColumnName2;

ALTER TABLE table_name MODIFY password varchar(20) AFTER id

DROP COLUMN Example

ALTER TABLE Persons DROP COLUMN DateOfBirth;

Alter Table Name:

ALTER TABLE old_table RENAME new_table;

DELETE TABLE VALUES

delete from newas where id=54;

truncate newtable;

SET SQL_SAFE_UPDATES = 0;

You might also like