Create Database and Table

get a list of available databases;

SHOW DATABASES;

create database

CREATE DATABASE AppleDb;

drop a database

DROP DATABASE AppleDb;

if the database doesn't exist in MySQL, then the drop command will return an error, hence it's better to use drop is exist

DROP DATABASE IF EXISTS AppleDb;

Creating a database doesn't automatically select it for use. it needs to be done explicitly.

USE AppleDb;

Database Should be Created only Once but Must be Selected Every Time Before Use

show tables present in the selected database

SHOW TABLES;

The Newly Created Database will Have no Tables

create a new table in the selected database

CREATE TABLE apple (
    apple_id BIGINT,
    apple_name VARCHAR(20),
    available CHAR(1),
    available_date DATE
);

to check the tables have been created successfully in the selected database;

SHOW TABLES;

to check the details of the table

DESCRIBE apple;

to drop table 

DROP TABLE IF EXISTS apple;

if the table doesn't exist in the database then the drop table command will return an error, hence it's better to use

DROP TABLE IF EXISTS apple;

follow us on