Description
The SQL Server (Transact-SQL) ALTER TABLE statement is used to add, modify, or drop columns in a table.
Add column in table
You can use the ALTER TABLE statement in SQL Server to add a column to a table.
Syntax
The syntax to add a column in a table in SQL Server (Transact-SQL) is:
ALTER TABLE table_name ADD column_name column_definition;
Example
Let's look at an example that shows how to add a column in an SQL Server table using the ALTER TABLE statement.
For example:
ALTER TABLE employees ADD last_name VARCHAR(50);
This SQL Server ALTER TABLE example will add a column to the employees table called last_name.
Add multiple columns in table
You can use the ALTER TABLE statement in SQL Server to add multiple columns to a table.
Syntax
The syntax to add multiple columns to an existing table in SQL Server (Transact-SQL) is:
ALTER TABLE table_name
ADD column_1 column_definition,
column_2 column_definition,
...
column_n column_definition;
DROP TABLE
Description
The SQL Server (Transact-SQL) DROP TABLE statement allows you to remove or delete a table from the SQL Server database.
Syntax
The syntax for the DROP TABLE statement in SQL Server (Transact_SQL) is:
DROP TABLE table_name;
Parameters or Arguments
- table_name
- The name of the table to remove from the SQL Server database.
Example
Let's look at an example that shows how to drop a table using the DROP TABLE statement in SQL Server (Transact-SQL).
For example:
DROP TABLE employees;
This DROP TABLE example would drop the table called employees from the current database in SQL Server.
Comments
Post a Comment