
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What is MySQL CREATE command? How can we create both database and table with this command?
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;
Example
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 ------------------------------);
Example
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’.
- Related Articles
- How to create a database on command line in MySQL?
- How can we establish MySQL database by using MySQL binary at command\nprompt?
- How can we create a table from an existing MySQL table in the database?
- How can we add multiple columns, with single command, to an existing MySQL table?
- How to generate a “create table” command based on an existing table in MySQL?
- How can we return to windows command shell from MySQL command line tool?
- How can we create our own choice MySQL database?
- Can we create a database with a numeric name with MySQL?
- How can we use WHERE clause with MySQL INSERT INTO command?
- How can we use MySQL ALTER TABLE command for adding comments on columns?
- How can we analyze the tables of a particular database from MySQL Server command line?
- How can we create user accounts in MySQL database server?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- MySQL command to copy table?
- Update MySQL table on INSERT command with triggers?

Advertisements