CREATE Statement on MYSQL


Create Database

Now let’s see how we can create a new database. However, we can’t create duplicate database with the same name of an existing database.


Syntax:

CREATE DATABASE databasename;

Query:

create database testdb;


Output
:

New database ‘testdb’ will be created

As you see above, we have just created a new database

Tester Usage Tips:

  • Create a new database for test data storage
  • Create a new database as backup of application database for testing
  • Create temporary database for testing ETL or Reports.

 

Create Table

Now as we have a database, we need to create a table to store and manipulate our required data.

Simply put table is nothing but a combination of rows and columns

Let’s create a new table by the name ‘Persons’ where we would want to store and manipulate a person’s basic demographics information.


Syntax
:

USE databasename

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ….
);

Query:

USE employees

CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);


Output
:

‘Persons’ table will be created with mentioned columns as above.

Create Table Example

As you see above new table ‘Persons’ is created with specified columns

Tester Usage Tips:

  • Create a new table for application data or test data storage and manipulation