Home Sql Mysql-table MySQL Create Table
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

MySQL Create Table

Advertisement
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

     

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:

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Related Tutorials

Ask Questions?    Discuss: MySQL Create Table  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
priya
February 21, 2012
find the error

create table UserMaster(userId varchar(10),loginame varchar(100),username varchar(100), EmailId varchar(100), PhoneNO Byte, Address varchar(200), Country varchar(50), State varchar(50), UStatus varchar(20));
shailendra singh
April 9, 2012
Create table

how to create of the table
DMCA.com