Mysql Alter Command

Mysql Alter Command define the list of Command used for removing 'Primary key','Unique index','Delete Column','Change column' etc.

Mysql Alter Command

Mysql Alter Command

     

Mysql Alter Command define the list of Command used for removing 'Primary key','Unique index','Delete Column','Change column' etc.

Understand with Example

The Tutorial illustrate an example from 'Mysql Alter Command'. To understand this example  we use Alter keyword that redefine the table 'tablename' and Drop primary key is used  to remove/delete the primary key in a table.  

SYNTAX:

 

 

 

For removing primary key:-

ALTER TABLE tablename DROP PRIMARY KEY;

For removing a Unique index:

The Alter table is used to modify the table 'table name' and remove the index 'index_name' from the existing 'tablename'. 

ALTER TABLE tablename DROP INDEX index_name;

Adding a primary key :

The Alter Table is used to modify table 'tablename' and add a primary key to the column 'index_column'.

ALTER TABLE tablename ADD PRIMARY KEY (index_columns);

Delete a column:

The given below Syntax uses 'Alter' table is used to redefine the table 'tablename' and drop query is used to delete the column name.

ALTER TABLE table name drop column column name;

Add a new column to db:

The below Query is used to modify the table 'tablename' and add a column 'columnname'.

ALTER TABLE tablename ADD Column columnname type;

Change column name:

The below Alter Table is used to modify the tablename and change the column name. 

ALTER TABLE tablename change oldcolumnname newcolumnname type;

Make a unique column:

The given below Query 'Alter Table' is used to modify the table  and add a unique column name.

ALTER TABLE tablename add unique columnname;

Delete unique from table:

The given below Query is used to modify the table and delete the column name from index.

ALTER TABLE tablename drop index columnname;

Alter a column size:

The Alter Table is used to modify the table and alter the size of column.

ALTER TABLE table name modify column name type;

Renaming a Table:

The Alter Table is used to modify the table and change the table name.

ALTER TABLE table name RENAME  To tablename;