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

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

Windows 11 Services Run Prompt

MySQL /

Start MySQL Server on Windows 11

MySQL Download Windows 11

MySQL /

Download & Install MySQL on Windows 11

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

Recent Posts

  • Flowchart Control structures
  • Draw a Square using Turtle Graphics
  • Flowgorithm File Errors
  • Write to Text File using Flowgorithm
  • Read Text File using Flowgorithm
  • Flowgorithm Turtle Graphics Flowchart
  • Update Flowgorithm to Latest Version
  • Flowgorithm File Symbols
  • Flowgorithm Turtle Graphics
  • Flowgorithm 3 New Features

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version