Create Table Statement

By | July 3, 2015

CREATE TABLE Statement is used to create a New Table (Relation) in database. Table is used to store information in the database.

Syntax:   Create Table command has the following form.

1

For each column, a name and a data type must be specified and the column name must be unique within table definition. Columns are separated by colons.

  • Not Null clause indicates that column can’t be empty.
  • Unique clause indicates that only distinct value is allowed in the column.
  • Column constraint and Table constraint specify the different constraint applied in the table.

Example: 

1.  Create Salesman Table

2

In this example, we have created SALESMAN table with SNUM as a Primary key (means you can’t insert duplicate values as well as SNUM is mandatory field) and SNAME as a mandatory field.

2.  Create Customer Table

3

In this example, we have created CUSTOMER table with CNUM as a Primary key, CNAME as a mandatory field and SNUM is the reference of SALESMAN table.

3.  Create Orders Table

4

In this example, we have created ORDERS table with ONUM as a Unique and mandatory field, SNUM is the reference of SALESMAN and CNUM is the reference of CUSTOMER.

Leave a Reply

Your email address will not be published. Required fields are marked *