SQL语句——alter用法

文章来自
SQL语句中ALTER的用法

The ALTER TABLE command allows you to add, modify, or drop a column from a existing table.

Adding column(s) to a table

Syntax #1

To add a column to an existing table, the ALTER TABLE syntax is:

1
ALTER TABLE table_name ADD column_name column_defination;

For example:

1
ALTER TABLE supplier ADD supplier_name varchar(50);

This will add a column called supplier_name to the supplier table.

Syntax #2

To add multiple columns to an existing table, the ALTER TABLE syntax is:

1
ALTER TABLE table_name ADD(
    column_1 column_1-defination,
    column_2 column_2-defination
);

For example:

1
ALTER TABLE supplier ADD(
    supplier_name varchar(50),
    city varchar(50)
);

This will add two columns(supplier_name, city) to the supplier table.

Modifying column(s) in a table