MySQL Create Table

Here, you will read the brief description about the MySQL create table. The CREATE TABLE statement is used for creating a table in database.

MySQL Create Table

--Ads--

MySQL Create Table

     

Here, you will read the brief description about the MySQL create table. The CREATE TABLE statement is used for creating a table in database. 

There are following way to create MySQL table:

 

 

 

 

 

 

 

 

Syntax: 

CREATE TABLE tablename(column1name type, column1name type,.........);

This is a basic CREATE TABLE statement that should work in any sql database.

Query: 

CREATE TABLE table_example(id int, name varchar(50),description varchar(200));

If you want to know about the created table then you write the following query:

Query: 

DESC table_example;

Output:

To create a table with a particular storage engine: 

If you create table without specifying the ENGINE option then server will use the default storage engine MyISAM. If you want to use other, storage types must be defined.

Query: 

CREATE TABLE table_example1(id int, name varchar(50),description varchar(200))ENGINE=innodb;

ENGINE=innodb is the method of defining the storage type.

Execute the Query "DESC table_example1;" to see the table structure:

Output:

To create a table with auto-increment: If you use auto-increment then you will be able to automatically assign the value to a specified column. The auto-increment property should not be null. In the table created from the query below, the data in the "id" column will be added automatically if not specified.

Query: 

CREATE TABLE table_example2(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, stuName varchar(50));

Execute the Query "DESC table_example2;" to see the table structure:

Output:

0