MySQL CREATE, DROP AND ALTER TABLE

  


CREATE TABLE

The CREATE TABLE statement is used to create a new table. 

SYNTAX:


create table table_name (column1_name datatype, 

column2_name datatype, 

column3_name datatype);


EXAMPLE:


The following SQL statement creates a Table called "student_details":


create table students_details (student_id int, 

student_name nvarchar(200), 

student_address nvarchar(200)); 


DROP TABLE

The DROP TABLE Statement is used to delete a existing Table. 

SYNTAX:


 drop table table_name;


EXAMPLE:


The following SQL statement drop a table called "students_details":


drop table students_details


ALTER TABLE

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table

ADD COLUMN

SYNTAX:


 alter table_name add column_name datatype;


EXAMPLE:


The following SQL statement add a table column called "students_email":


alter student_details add (students_email nvarchar(200));


DROP COLUMN

SYNTAX:


 alter table_name drop column column_name;


EXAMPLE:


The following SQL statement drop a table column called "students_email":


alter student_details drop column students_email;


RENAME COLUMN

SYNTAX:


 alter table_name rename column column_oldname to column_newname;


EXAMPLE:


The following SQL statement rename a table column called "students_address to students_lastname":


alter student_details rename column students_address to students_lastname;