Slide 11.6: SQL (Structured Query Language)
Slide 11.8: The INSERT INTO statement
Home

The CREATE TABLE Statement


The syntax of creating a table in a database is given on the right.
   CREATE TABLE  table_name (
     column_name1  data_type,
     column_name2  data_type,
     ....... )

The example on the right demonstrates how to create a table named Persons, with four columns: LastName, FirstName, Address, and City:
  SQL> create table  Persons (
    2    LastName   varchar(32),
    3    FirstName  varchar(32),
    4    Address    varchar(64),
    5    City       varchar(16) );

  Table created.

The data type specifies what type of data the column can hold. The table below contains the most common data types in SQL:

Data Type Description
integer(size)
int(size)
smallint(size)
tinyint(size)
Hold integers only. The maximum number of digits are specified in parenthesis.
decimal(size,d)
numeric(size,d)
Hold numbers with fractions. The maximum number of digits are specified in “size.” The maximum number of digits to the right of the decimal is specified in ‘d’.
char(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis.
varchar(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis.
date(yyyymmdd) Holds a date.