a
 
SQLRef.Com 

            SqlRef.Com


SQL BASIC
DATA QUERY LANGUAGE
BASIC FUNCTION
AGGREGATE FUNCTION
DATA MANIPULATION LANGUAGE
DATA DEFINITION LANGUAGE
DATA CONTROL LANGUAGE
OTHERS

CREATE TABLE

CREATE TABLE <table>
  ( <field> <data type> [NULL|NOT NULL] [constraint],
    <field> <data type> [NULL|NOT NULL] [constraint],
     ...
  )

You can create table with the CREATE TABLE command. You can specify name and data type for each columns and possibly some simple constraints. The [NULL | NOT NULL] is to indicate whether the field can accept NULL value or not when inserting new records. If NOT NULL is selected, a value must be supplied to the field when a record is inserted, otherwise, an error will be returned. If you do not specify whether to accept NULL or Not, a default option will be taken.  Please take note that different database vendor may default the NULL option differently. For example, Ms SQL and Sybase will default it to NOT NULL while Oracle, DB2 and MySql will default it to NULL. This is something you need to take note if you want to migrate from one database to another. If you want to ensure higher database portability, you must specify the NULL or NOT NULL option explicitly so that you do not rely on the default option. [constraint] will defines the value that can be inserted into the field or action to be taken when record is inserted based on the constraint criteria.

The following SQL statement creates an Employee table with 8 fields.

CREATE TABLE EMPLOYEE

(
   EmployeeID INTEGER NOT NULL,
   FirstName    CHARACTER (15),
   LastName     CHARACTER (20) NOT NULL,
   Street          CHARACTER (25),
   City             CHARACTER (20),
   State           CHARACTER (2),
   Zipcode       INTEGER,
   Phone          CHARACTER (13)

)


Table: Employee
EmployeeID FirstName LastName Street City State Zipcode Phone
               
               



 
| Freebies | Free Trial | Add to Bookmark | Search | Link to Us |
Copyright © 2006 SqlRef.com. All rights reserved.