SQL create table example – Learn how to create a table in MySQL database with example and important points.

Create Table statement allows you to create and define a table in  an existing SQL database you have created. You can learn how to create a database in SQL.

SQL syntax to create a table

Here is the syntax of creating a table .

Syntax: CREATE TABLE [IF NOT EXISTS]  [table_name](

column_list datatype

)engine=table_type;

Points to notice:

  • Title of the table must be written after “create table” statement.
  • White spaces are not allowed for tables name.

Example :  BOOKSSTORE

  • _ is allowed for table name.
  • Column headings must define with in the parentheses by specifying the required data type .

 SQL query example to create a table

CREATE TABLE BOOKS

(ISBN_NO VARCHAR(15) NOT NULL PRIMARY KEY,

TITLE VARCHAR(100) NULL,

AUTHORFIRSTNAME VARCHAR(40) NULL,

AUTHORLASTNAME VARCHAR(40) NULL

);

SHOW LIST OF TABLES

SQL syntax to show list of tables exist in the database.

Syntax:
SHOW [EXPRESSION]

Here is the query to display list of tables that exist in the database BOOKSTORE.

Query Example:
SHOW TABLES;

This SQL query will produce following output:

Tables_in_bookstore
addressbook
books
orderdetails

Related Posts