ALTER Command Tutorial in PHP

Features of MySQL ALTER Command :

1) Add Column in a Table

2) Changing Data Type of a Column

3) Change Column Name

4) Adding Constraints to a Column

5) Changing Column Position

6) Delete Column

7) Renaming Tables


ALTER Syntax :

1) For Add Column :

ALTER TABLE table_name ADD column_name datatype;

2) For Modify Column :

ALTER TABLE table_name MODIFY column_name datatype;

3) For Delete Column :

ALTER TABLE table_name DROP COLUMN column_name datatype;

4) For Rename Column :

ALTER TABLE table_name CHANGE column_name New_name datatype;

5) For Rename Table :

ALTER TABLE table_name RENAME new_table_name;


If we want to Add Extra Column named "Email" in table named "students" then we can use below shown sql query :

ALTER TABLE students ADD Email varchar(100);


If we want to place "Email" column after "name" column then in "students" table then we can use below shown sql query :

ALTER TABLE students MODIFY Email varchar(100) AFTER name;


If we want to change data type of column named "Email" in "students" table then we can use below shown sql query :

ALTER TABLE students MODIFY Email INT(10);


If we want to apply UNIQUE value to Column named "Email" in table named "students" then we can use below shown sql query :

ALTER TABLE students ADD UNIQUE(Email);


If we want to change the name of column named "Email" in table named "students" then we can use below shown sql query :

ALTER TABLE students CHANGE Email Email_id varchar(100);


If we want to delete column named "Email_id" from table named "students" then we can use below shown sql query :

ALTER TABLE students DROP COLUMN Email_id;


If we want to change the table name from "students" to "students_make" then we can use below shown sql query :

ALTER TABLE students RENAME students_make;


If we want to add new records from any particular Index in column For Example, if we want to add new records in column from Index 4 then we can use below shown sql query :

ALTER TABLE students AUTO_INCREMENT = 4;

Comments

Popular posts from this blog

GROUP BY Clause and HAVING Clause in PHP

Method Overriding in Traits in PHP

Mysqli database Connection and Display Table Data from Database