SQL Server provides Alter and Drop commands for dropping tables and Database,
as well changing the structure of Table.
i.
Drop
This command is used to drop the Table
or Database. We can use the command is the following way:
Drop
Table Dept -
This command will drop the table named “DEPT”
Drop Database Test - This command will drop the database named “TEST”
ii.
Alter
This command is used to alter the
Structure of Table. We can add, remove columns or even constraints with the
help of this command.
Alter
table emptemp add address varchar(20)
The above command
will add a new column named “address” in the table called “emptemp”
Alter
table emptemp drop column address
The above command
will delete column named “address” in the table called “emptemp”
Alter
table emptemp alter column address varchar(200)
The above command
will change the column length to 200 for address.
iii.
Renaming Table
We can also rename a SQL Server table.
The following command depicts renaming of the table named “emptemp” to “empnew”
sp_rename 'emptemp', 'empnew'
Comments