ALTER TABLE Statement (SQL ALTER TABLE Statement)

 

ALTER TABLE is used to change the structure of an existing data table. The syntax is as follows:

ALTER TABLE table_name ...;

Assuming that we have now created a "customers" data table:

C_IdNameAddressPhone

Next, how do we...

Add column (ADD COLUMN)

grammar

ALTER TABLE table_name ADD column_name datatype;

For example, if we want to add a Discount field:

ALTER TABLE customers ADD Discount VARCHAR(10);

Change field data type (ALTER COLUMN TYPE)

grammar

ALTER TABLE table_name ALTER COLUMN column_name datatype;

For example, to change the data type of the Discount field:

ALTER TABLE customers ALTER COLUMN Discount DECIMAL(18, 2);

Delete column (DROP COLUMN)

grammar

ALTER TABLE table_name DROP COLUMN column_name;

For example, to delete the Discount field:

ALTER TABLE customers DROP COLUMN Discount;

Post a Comment

0 Comments