Modifying Tables

Modifying Column

Modify the data type of a column:

ALTER TABLE tb1C MODIFY name VARCHAR(100);

Add a new column to the end:

ALTER TABLE tb1C ADD birth DATETIME;

Add a new column to the beginning:

ALTER TABLE tb1C ADD birth DATETIME FIRST;

Add a new column to a specific location:

ALTER TABLE tb1C ADD birth DATETIME AFTER empid;

Modify the ordering of columns:

ALTER TABLE tb1C MODIFY birth DATETIME FIRST;

Change the name and date type of a column:

ALTER TABLE tb1C CHANGE birth birthday DATE;

Drop a column:

ALTER TABLE tb1C DROP birthday;

Primary Key and Unique Key

Set primary key (no duplication + no NULL):

Set unique key (no duplication):

Auto-Increment and Default Value

Set auto-increment:

Reset auto-increment index (deletion won't set the counter to 1):

Set default value for a column:

Index

Create index:

Show index (in a nice format):

Drop index:

Last updated

Was this helpful?