SQL ALTER TABLE STATEMENT

SQL ALTER TABLE STATEMENT

SQL ALTER TABLE STATEMENT

The ALTER TABLE statement is used to add, delete, or modify columns in anĀ 

existing table.

SYNTAX

To add a column in a table, use the following syntax:

ALTER TABLE table_ name ADD column_ name datatype

SYNTAX

To delete a column in a table, use the following syntax

ALTER TABLE table_ name DROP COLUMN column_name


SYNTAX

To change the data type of a column in a table, use the following syntax:

ALTER TABLE table_ name ALTER COLUMN column_name datatype

EXAMPLE

P_Id                 LastName          City

1                       Jameson           John

2                          Smith              Kate

3                      Kristensen          Olya

EXAMPLE

ALTER TABLE Persons ADD Date 0f Birth date

RESULT

P_Id      LastName       FirstName        DateOfBirth

1            Jameson            John

2            Smith                  Kate

3            Kristensen          Olya

Leave a Reply

Your email address will not be published.