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:
|CREATE TABLE tablename(column1name type, column1name type,.........);|
This is a basic CREATE TABLE statement that should work in any sql database.
|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:
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.
|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:
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.
|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:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.