Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle Create Table

The CREATE TABLE statement is used to create a database table. A table creation statement requires three parameters. The name of table specify table name in database. The column parameters specify the names of the columns of the table. The datatype parameter specifies the type of data to be store (e.g. varchar, integer, date, etc.).

Tip: In order to get compelet details of the available data types, go to our Oracle Data Types section.

Oracle Create Table Syntax

Syntax

CREATE TABLE table_name (
    column_name1 datatype,
    column_name2 datatype,
    column_name3 datatype,
   ....
);

Oracle CREATE TABLE Example

The following Oracle statement creates a table called "tblCustomerLoan":

Example

CREATE TABLE tblCustomerLoan(
	pk INT NOT NULL,
	firstName varchar(50) NULL,
	lastName varchar(50) NULL,
	address varchar(150) NULL
);

Note:

In the above example, The pk column is of type int NOT NULL and will hold an integer. The NOT NULL is a field attribute and it is used to make sure field should not be NULL.

The firstName, lastName and address fields are of type varchar and will hold characters with specified length. The NULL is a field attribute and it is used to allow NULL value to be stored.

Oracle CREATE TABLE Example with Primary Key

The following Oracle statement creates a table called "tblCustomerLoan":

Example

CREATE TABLE tblCustomerLoan(
	pk INT NOT NULL,
	firstName varchar(50) NULL,
	lastName varchar(50) NULL,
	address varchar(150) NULL,
	CONSTRAINT customers_pk PRIMARY KEY (pk)  
);

Primary Key:

A primary key is a single field or combination of fields that contains a unique record. The primary key can not be null value. A table can have only one primary key.