SQL Tutorial


      Basics

    1. Introduction
    2. Database Structure

      Commands

    3. Create
    4. Select
    5. Insert
    6. Update
    7. Delete
    8. Drop

      Operations

    9. Joining Tables

      Appendices

    10. Terms
    11. Credits

SQL Create Command

This command is used to create a table. The syntax of this command is:

create table tablename
(column1name datatype [constraint],
column2name datatype [constraint], 
column3name datatype [constraint]);

Keywords specifying Items that may be created

  • table

Data Types

  • char(size) - Fixed length string of characters of the set size. The size of the string is limited to 255 characters.
  • date
  • number(maxsize) - Number with a maximum number of digits specified by "maxsize".
  • number(maxdigits,maxright) - A decimal number with a manimum number of "maxdigits" with "a maximum number of digits to the right of the decimal, "maxright".
  • varchar(maxsize) - A character string with variable lingth limited to "maxsize".

Constraints

Constraints are rules for the column.. Possible values include:

  • not null - The column values must have a value and cannot be null.
  • primary key - Each record is uniquely identified by this column.
  • unique - No two values may be the same in the column

Example

create table citylist
(name varchar(20),
state varchar(20),
population number(8),
zipcode number(5) unique);