TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL DROP TABLE Statement

Overview

In this tutorial, we will learn MySQL DROP TABLE statement with examples. The DROP TABLE removes one or more tables. All the table data and the table definition will be removed.

A DROP TABLE statement cannot be undone. This is a destructive statement, so be careful and use caution when executing this statement.

Syntax

The general syntax for the statement is as follows:

mysql> DROP [TEMPORARY] TABLE [IF EXISTS] <database_table_name>

We can also use the DROP statement to drop multiple database tables. We must have the DROP privilege for dropping each table.

mysql> DROP [TEMPORARY] TABLE [IF EXISTS] <table_name1> [{, <table_name2>}…]

 

The TEMPORARY keyword drops only the TEMPORARY tables. A TEMPORARY table is visible only to the client that created it. TEMPORARY keyword is a good way  to ensure that we do not accidentally drop a non-TEMPORARY table.

Use IF EXISTS to prevent an error from occurring for tables that do not exist in the database. A NOTE message is generated for each non-existent table when using the IF EXISTS clause in the statement.

Examples

Let’s drop a table R_Actor from the database.

mysql> DROP TABLE IF EXISTS R_Actor;
Query OK, 0 rows affected (0.10 sec)

A successful DROP statement returns Query OK message. We can verify using the SHOW TABLES command. The table should be deleted from the list.

Warnings non-existent table

mysql> DROP TABLE IF EXISTS non_existent_table;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SHOW WARNINGS;
+——-+——+——————————————-+
| Level | Code | Message |
+——-+——+——————————————-+
| Note | 1051 | Unknown table ‘sakila.non_existent_table’ |
+——-+——+——————————————-+
1 row in set (0.00 sec)

mysql>

DROP TABLE Statement Warnings

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ MySQL CREATE TEMPORARY TABLE Statement› MySQL Import using SQL file

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version