THE SQL ALTER  Clause is used to add, drop or modify the existing constraints records in a table.

ALTER TABLE ADD COLUMN SYNTAX

150.png

ALTER TABLE DROP COLUMN SYNTAX

151.png

ALTER TABLE ALTER/MODIFY COLUMN SYNTAX (SQL SERVER)

152.png

ALTER TABLE ALTER/MODIFY COLUMN SYNTAX (MYSQL)

153.png

ALTER TABLE ALTER/MODIFY COLUMN SYNTAX (ORACLE 10 G)

154.png
 

Where,

  • ALTER                                             : keyword used to update/modify the column in table.

  • Table_name                                    : The name of the table from where you want to ALTER

  • Column1Name, Column2Name       : The name of the columns of the table which you want to ALTER

  • DROP COLUMN                               : KEYWORD used to drop a column

  • MODIFY                                           : KEYWORD use to change the data type of a column in a table

 

EXAMPLE

Let us consider a demo database with table name Persons.

155.png

Figure 39.1. Select * from Persons;

Let’s Add a column to PersonalInfo Table named as AGE

156.png
157.png

Figure 39.2 ALTER COMMAND QUERY OUTPUT

 

PRACTICE YOURSELF

158.png