SQL DROP Query

What is DROP query?

Definition: Drop query means to erase something from database or complete database with all information related to that.

In sql, DROP query is used with table and database. You may also use truncate command to remove data from table.

  • DROP Tables
    In this case, you may drop the table from database. While you use this query, make sure
    before you use it because it will remove all information which are related to tables. For example primary key, foreign key, constraints, triggers, permissions, property of table etc...
  • Truncate Table
    You may also use Truncate command to delete all information from database table. This command will remove all data from database table only.
  • DROP Databases
    Here, you may remove whole database from DBMS. This will also remove all details which
    are in database. For example Tables, Views, User Defined Functions, Triggers, Cursors, Permissions etc...

Why DROP query needed?

When we required to removes unnecessary data, objects or permissions from database, we can use this DROP query. But, by using this query, it is necessary to make sure to take decision to remove it. Because this will remove everything forever.

Let’s understand syntax and example for database and table.

  • Drop Table

    Syntax:
    DROP TABLE TABLENAME;

    Example:
    DROP TABLE Employee;

  • Truncate Table

    Syntax:
    TRUNCATE TABLE TABLENAME;

    Example:
    TRUNCATE TABLE Employee;

  • Drop Database

    Syntax:
    DROP DATABASE DATABASENAME;

    Example:
    DROP DATABASE Database_ Employee;

Important: Be careful while using all above three sql query. Because by using them, you will be lost all information related to object permanent.