By 25/02/2016 1 Comments

What Is ALTER TABLE Statement In SQL?

  • SQL ALTER TABLE statement is used to change/modify, delete or add columns of an existing table in database.
  • SQL ALTER TABLE statement uses ADD keyword for add a new column, DROP keyword for delete/drop an existing table column and MODIFY keyword for change/update an existing table column.

Syntax: Add a new column

ALTER TABLE table_name
ADD column_name datatype;

Example:

ALTER TABLE city
ADD description VARCHAR(220);
  • In above example the ALTER TABLE statement will add a new column (description) in a table (city).

Syntax: Delete/Drop an existing column

ALTER TABLE table_name
DROP COLUMN column_name;

Example:

ALTER TABLE city
DROP COLUMN description;
  • In above example the ALTER TABLE statement will delete/drop a column (description) from a table (city).

Syntax: Change/Modify an existing column’s data type (SQL Server, MS Access)

ALTER TABLE table_name
ALTER COLUMN column_name datatype;

Syntax: Change/Modify an existing column’s data type (MySQL, Oracle)

ALTER TABLE table_name
MODIFY COLUMN column_name datatype;

Example: MySQL

ALTER TABLE products
MODIFY COLUMN p_date DATETIME;
  • In above example the ALTER TABLE statement will change/modify a data type of column (p_date) to DATETIME in a table (city).






Posted in: Sql

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .