Instagram
youtube
Facebook
Twitter

MS SQL Server- Drop table

MS SQL Server- DROP table

  • Drop table means deleting a table, complete data, and whole definition.
  • There are mainly two ways to remove a table in SQL Server: SQL Server Management Studio and Transact-SQL Command.

Using SQL Server Management Studio

  • In Object Explorer, click on the '+' to expand the Database folder.
  • Select the database and click on the '+' to expand the selected database.
  • Select the tables folder, right-click on the desired table then select the delete option from the pop menu.
  •  After clicking on the Delete option, the Delete Model Object box appears to confirm the deletion process. Click on OK.
  • Once the table is deleted, click on refresh or press F5 and see the name of the table that will disappear from the list of tables in the selected database.

Using T-SQL command

  • Syntax to drop a table:
DROP TABLE [IF EXISTS] [database_name.][schema_name.]table_name;  
  • database_name is the name of the database where a table is stored 
  • Schema_name indicates the schema table belongs.
  • table_name is the name of the table you want to delete.
  • IF EXIST is an optional clause that indicates the table will be deleted if it exists in databases.
  • Syntax to drop Multiple tables:
DROP TABLE [IF EXISTS] [database_name.][schema_name.]table_name1,[schema_name.]table_name2 ,[schema_name.]table_name3..;