Saturday, March 10, 2018

Oracle Database Create Table

Oracle Create table command used to create table in oracle database.

Table is main oracle entity used to store data in oracle database.


Oracle Create Table Syntax:
In Oracle create table syntax user need to specify Table name and Columns like below,

Create Table Table_Name
{
Column_Name1 DataType,
Column_Name2 DataType,
Column_Name3 DataType,
......
......
Column_NameN DataType
};

In above create table syntax Table_Name can be any name that user want to name table. Column_Name1  can be any name that user wants to give to its column.Every column must  have Datatype. Datatype can be anything i.e. varchar,Number,date etc.We will detaily discuss about oracle datatype in upcoming posts.

We can also specify oracle column value should be null or not by specify NULL or NOT NULL in create table command as like below,

We can specify column NULL like below in create table query then value of the column can be null

Create Table Table_Name
{
Column_Name1 DataType NULL,
Column_Name2 DataType NULL,
Column_Name3 DataType NULL,
......
......
Column_NameN DataType NULL
};

So if we specify column NULL like above then we have to compulsory specify value to column while inserting record.


We can specify column NOT NULL like below in create table query then value of the column can not be null.

Create Table Table_Name
{
Column_Name1 DataType NOT NULL,
Column_Name2 DataType  NOT NULL,
Column_Name3 DataType NOT NULL,
......
......
Column_NameN DataType NOT NULL
};

So if we specify column NOT NULL like above then we can exclude column or set blank value to column while inserting record.

Create Primary Key :
Primary key is used to uniquely identify the record from table. Primary key should not be NULL.

We can specify column as primary key like below,
Constraint Constraint_Name PRIMARY KEY(Column_Name)

Here Constraint_Name can be anything and Column_Name must be table column that we have to assign as primary key.

So create table command look like below,

Create Table Table_Name
{
Column_Name1 DataType NOT NULL,
Column_Name2 DataType  NOT NULL,
Column_Name3 DataType NOT NULL,
......
......
Column_NameN DataType NOT NULL
Constraint Constraint_Name PRIMARY KEY(Column_Name1)
};


Click Here for ALTER TABLE ORACLE article.

0 comments:

Post a Comment