DROP

DROP in SQL is a statement used to delete the entire structure or scheme of a database object. It is predominantly employed to remove tables, databases, or other relational database management system objects from the database. Once the object is dropped, it cannot be recovered.

Example

DROP DATABASE testDB;

Output

Query OK, 0 rows affected (0.03 sec)

Explanation

The DROP DATABASE statement is used to delete a database in SQL. In the provided example, the database named “testDB” is deleted. The output indicates that the query was successful and no rows were affected as it was a database-level operation, not a table-level operation.

Example

DROP TABLE IF EXISTS example_table;

Output

DROP TABLE

Explanation

The SQL statement above deletes the table named ‘example_table’ if it exists in the database. If the table does not exist, nothing happens and no error message is produced due to the IF EXISTS clause. The output DROP TABLE indicates the operation was successful.

Example

CREATE DATABASE TestDB;
DROP DATABASE TestDB;

Output

Command(s) completed successfully.

Explanation

In the example, a database named “TestDB” is first created and then dropped, which means it’s deleted. ‘Command(s) completed successfully.’ message indicating that the operation has been completed successfully.

Example

DROP TABLE employees;

Output

Table EMPLOYEES dropped.

Explanation

The DROP TABLE statement is used to delete a table in Oracle. The statement deletes the entire table structure and associated data. The specific command “DROP TABLE employees;” will delete the table employees from the database. If the table is successfully deleted, Oracle will output “Table EMPLOYEES dropped.”.

Example

CREATE TABLE temp_table(
id INTEGER PRIMARY KEY,
name TEXT
);
INSERT INTO temp_table(id, name)
VALUES (1, 'Example Name');
DROP TABLE temp_table;

Output

Query OK, 0 rows affected (0.00 sec)

Explanation

In the above example, a temporary table, temp_table, is first created and populated with a dummy row of data. The DROP TABLE statement is then used to remove this table from the database entirely. As no rows are directly affected by the table deletion, the output of the DROP TABLE operation is 0 rows affected.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.