What is MySQL CREATE command? How can we create both database and table with this command?

MySQLMySQLi Database

CREATE command is a DDL command which is used to create a table or a database. The syntax for creating table and database with CREATE command is as follows −

The syntax for creating a database −

Create database database-name;


mysql> Create database query;
Query OK, 1 row affected (0.04 sec)

In the example above we have created a database named ‘query’.

The syntax for creating a table −

Create table table-name(
   column-name1 datatype1,
   column-name2 datatype2,
   column-name3 datatype3,
   column-name4 datatype4


mysql> Create table Employee(Id INT, Name Varchar(20));
Query OK, 0 rows affected (0.19 sec)

In the example above, we have created a table named ‘Employee’ having two columns ‘Id’ and ‘Name’.

Published on 19-Feb-2018 07:52:29