The Wayback Machine - https://web.archive.org/web/20211206145057/https://www.geeksforgeeks.org/sql-drop-table-statement/
Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

SQL Drop Table Statement

  • Last Updated : 27 Sep, 2021

SQL is a programming language used to manipulate data that are stored in the database. It is flexible and user-friendly. In SQL, to interact with the database, the users have to type queries that have certain syntax, e.g., the drop command. The drop command in SQL is used to remove the whole table including data present inside it, indexes, triggers, constraints, and permission specifications for that particular table. It is basically a DDL(data definition language) which is irreversible in nature. It means that once the user drops a table, there is no way to undo the command. Therefore, the drop command must be used with extensive care. It can also delete a whole database or can simply delete a table, it depends on the wish of the user.

Syntax:

Hey! Looking for some great resources suitable for young ones? You've come to the right place. Check out our self-paced courses designed for students of grades I-XII. 

Start with topics like Python, HTML, ML, and learn to make some games and apps all with the help of our expertly designed content! So students worry no more, because GeeksforGeeks School is now here!

 



To drop table:

DROP TABLE table_name;

To drop database:

DROP DATABASE database_name;

Example 1: Drop the table

In this example, we will discuss how to drop a table named “categories” from a database named “Newcafe”.

Step 1: Create a database

CREATE DATABASE Newcafe;

Step 2: Use a database

USE Newcafe;

Step 3: Create a table

CREATE TABLE [dbo].[categories]
(
    [CategoryID] INT NOT NULL PRIMARY KEY, 
    [CategoryName] NVARCHAR(50) NOT NULL,
    [ItemDescription] NVARCHAR(50) NOT NULL
);
GO

Add data inside a table



INSERT INTO [dbo].[categories]
( 
    [CategoryID], [CategoryName], [ItemDescription]
)
VALUES
( 
    1, 'Beverages', 'SoftDrink'
),
( 
    2, 'Condiments', 'Sweet and Savoury sauces'
), 
( 
    3, 'Confections', 'Sweet bread'
)
GO

View the final table:

SELECT * FROM  categories;

Image

Step 4: Drop the categories table

drop table categories;

Image

Example 2: Drop the database

Now we drop the above create the database using the following command:

drop database Newcafe;

Image

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!