DROP statement in MySQL




Hello and welcome everyone. In this article, we will learn about the DROP statement in MySQL. Let’s go.

MongoDB with .Net Core course link => https://www.udemy.com/mongodb-with-net-core-sagar-jaybhay/

Web API 2- .Net Core In depth In 5 Hours click on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/

The MySQL DROP statement removes or deletes the complete data with structure. Table structure means table definition, partitions, partitions stored all data, partition definitions. You can drop database or drop table using DROP statement, but be careful with DROP statement because deleting an existing database or table data it will not be recovered. You can drop or delete one or more database or table from an existing MySQL server or existing database. Before you delete or drop database or table, you need to back up for database or that particular table and it will help to you recover deleted or dropped database or table structure with the data.

DROP DATABASE
Using a DROP DATABASE statement you can drop or delete the database from MySQL server.
          Syntax:
                   DROP DATABASE IF EXISTS database_name;
Using the above syntax you need to specify the database name that you want to drop or delete the database. If database name does not exist and you want to delete then MySQL throws an error message.

DROP TABLE
Using a DROP TABLE statement you can drop or delete the existing table from the database.
          Syntax:
                   DROP TABLE IF EXISTS table_name;
Using the above syntax you can delete or drop existing table, but you need to specify the table name. If the table name does not exist and you want to delete or drop table then MySQL throws an error message.

Before looking example of DROP database and DROP table, we will create a database, table and insert some data in that.
Firstly we will create a database:

          CREATE DATABASE IF NOT EXISTS employee_DB;

Second, we will create a table:

          CREATE TABLE IF NOT EXISTS employee (
                   e_id int (10) PRIMARY KEY,
                   e_firstname varchar (50) NOT NULL,
                   e_lastname varchar (50) NOT NULL,
                   e_age int (10),
                   e_address varchar (250)
e_sex char (1)
e_phonenumber int (15) NOT NULL
)

Third one is we will insert some data in employee table:
         
  INSERT INTO employee (
  ‘e_id’, ’e_firstname’, ’e_lastname’,
  ’e_age’, ’e_city’, ’e_sex’,
  ’e_phnumber’
)
VALUES
  (
    1, ‘Hone’, ‘Reus’, 25, ‘San Jose’, ‘M’, ‘ + 1 555 555 1111’
  ),
  (
    2, ‘Cries’, ’Fence’, 23, ’Fresno’, ’F’, ’ +1 555 555 1111’
  );

Final Result
‘e_id’ ’e_firstname’ ’e_lastname’ ’e_age’ ’e_city’  ’e_sex’ ’e_phnumber’
  1     Hone        Reus     25   San Jose    M     +1 555 555 1111
 2      Cries        Fence    23     Fresno     F     +1 555 555 1111

Now I want to drop or delete employee table

          DROP TABLE IF EXISTS employee;
          It will drop the table from the employee_DB database. Remember one thing here deleted table data or structure; it will not recover after dropping.

Now I want to drop or delete the employee_DB database.

          DROP DATABASE IF EXISTS employee_DB;
          It will drop the database from the MySQL server and it will not recover after dropping database data or structure.

In this article, we learned about MySQL DROP statement. Using drop statement you can drop the existing database from the MySQL server and existing table from the database. Dropped database or table not recovered. So be careful before dropping database or table data.

MongoDB with .Net Core course link => https://www.udemy.com/mongodb-with-net-core-sagar-jaybhay/

Web API 2- .Net Core In depth In 5 Hours click on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/




Comments

Popular posts from this blog

ALTER statement in MySQL

MySQL Constraint – PRIMARY KEY

Order By Clause in MySQL