Defining Tables with the CREATE TABLE Statement

The process of creating a table is far more standardized than the CREATE DATABASE statement. Here's the basic syntax for the CREATE TABLE statement:

CREATE TABLE table_name
(     field1 datatype [ NOT NULL ],
      field2 datatype [ NOT NULL ],
      field3 datatype [ NOT NULL ]...)

A simple example of a CREATE TABLE statement follows:

SQL>
						CREATE TABLE BILLS (
  2   NAME CHAR(30),
  3   AMOUNT NUMBER,
  4   ACCOUNT_ID NUMBER);

Table created.

MySQL example:

mysql> create table bills
    -> (name         char(30),
    -> amount        numeric,
    -> account_id    numeric);
Query OK, 0 rows affected (0.07 sec)

This statement creates a table named ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.