website logo
⌘K
🏠Homepage
👋Introduction
Key Concepts & Architecture
🚀Getting Started
👨‍💻SQL Reference
SQL Queries
SQL Clauses
SQL Data Types
SQL Functions
Schema
🚨Error Handling
🆚Differences Between Oxla vs. PostgreSQL
Docs powered by archbee 

DROP statement

10min

This tutorial explains how to use the DROP TABLE query with its syntax and an example.

Overview

In this section, we will learn how to delete the data from a table using the DROP query.

⚠️ Watch out! Running a DROP query will also delete all existing records from the table.

Syntax

The basic syntax for the DROP query is as follows:

Syntax
|
DROP TABLE table_name;


In this syntax, we have several elements that are elaborated on below.

  1. DROP represents the statement name.
  2. TABLE entity type you want to drop.
  3. table_name defines which table you want to remove.

The DROP example below is executed in the public schema. You can also drop a table from another specific schema. Click here for more info.

Example

We have a table named warehouse that stores the product's id, name, and quantity:

Create a table
|
CREATE TABLE warehouse (
  id int,
  product string,
  qty int
);
INSERT INTO warehouse 
    (id, product, qty) 
VALUES 
    (889771,'Shirt',22),
    (777821,'Hat',99),
    (103829,'Bed Cover',12);

Display the table
|
 SELECT * FROM warehouse;


It will create a table as shown below:

The warehouse table
|
+---------+------------+---------+
| id      | product    | qty     | 
+---------+------------+---------+
| 889771  | Shirt      | 22      |
| 777821  | Hat        | 99      |
| 103829  | Bed Cover  | 12      |
+---------+------------+---------+



1) Use the following query to delete the warehouse’s table:

Drop the table
|
DROP TABLE warehouse;


2) If you have successfully run the query, you will get the following output: the table and the values within it are deleted.

Drop the table
|
DROP TABLE

Query returned successfully in 284 msec.


😥 If you attempt to use the table for any operation, you will find that the table no longer exists.



Updated 11 May 2023
Did this page help you?
Yes
No
PREVIOUS
SELECT statement
NEXT
SHOW TABLES statement
Docs powered by archbee 
TABLE OF CONTENTS
Overview
Syntax
Example

Dedicated to data analytics that provides 10x faster execution of analytical queries than current state of the art solutions. We are launching SOON! Join the waiting list for more info.




©2022 Oxla