Learn MySQL for Developing Web Application

Learn to build web applications with PHP and MySQL, Start your own blog, e-commerce site. In this tutorial you will learn queries of MySQL and MySQLi.

SQL CREATE Table


Tables are a basic unit of organization and storage of data in SQL. Each table has a name such as an author, book_mast, purchase or orders. A table is similar to a file in a non-database system.

Tables are organized into rows and columns. Each row represents a record, and each column can be thought of as representing a component of that record.

Syntax:

CREATE TABLE table_name(
column1 datatype[(size)],
column2 datatype[(size)],
column3 datatype[(size)],
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);

Parameters:

Name Description
table_name Name of the table where data is stored.
column1,column2 Name of the columns of a table.
data_type Char, varchar, integer, decimal, date and more.
size Maximum length of the column of a table.

CREATE TABLE is the keyword telling the database system what you want to do. In this case, you want to create a new table. The unique name or identifier for the table follows the CREATE TABLE statement.

Then in brackets comes the list defining each column in the table and what sort of data type it is. The syntax becomes clearer with the following example.