close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com



MySQL - ALTER TABLE

ALTER is used to update a Table content.

The ALTER TABLE statement is used to add, modify or delete columns in an existing table. It is also used to rename a table.

You can also use MySQL ALTER TABLE command to add and drop various constraints on an existing table.

ALTER TABLE - ADD Column

ADD is used to add columns into the existing table.

If you want to add columns in MySQL table, the MySQL alter table syntax is given below:

Syntax : ALTER Table Add


ALTER TABLE table_name
ADD column_name datatype;                    
                

The following MySQL adds an "Email" column to the "Students" table:

Example : ALTER Table Add


ALTER TABLE Students
ADD Email varchar(20);                   
                

ALTER TABLE - DROP COLUMN

DROP is used to delete columns into the existing table.

If you want to delete columns in MySQL table, the MySQL alter table syntax is given below:

Syntax : ALTER Table Drop


ALTER TABLE table_name
DROP COLUMN column_name;                 
                

The following MySQL delete an "Email" column to the "Students" table:

Example : ALTER Table Drop


ALTER TABLE Students
DROP COLUMN Email;                 
                


ALTER TABLE - ALTER/MODIFY COLUMN

ALTER/MODIFY is used to modify columns into the existing table.

If you want to modify columns in MySQL table, the MySQL alter table syntax is given below:

Synatax : ALTER Table Alter/Modify

Synatax : ALTER Table Alter/Modify


ALTER TABLE table_name
ALTER COLUMN column_name datatype;               
                

The following MySQL modify an "NAME" column to the "Students" table its value of charcter length from 20 to 40.

Example : ALTER Table Modify


ALTER TABLE Students
ALTER COLUMN  NAME varchar(40);