Create table in Oracle
This article describes how to create a table in Oracle
The basic statement for creating a table is:
CREATE TABLE TABLE_NAME (
kol_1 datatype {NULL|NOT NULL}
, kol_2 datatype {NULL|NOT NULL}
, ..
, kol_n datatype {NULL|NOT NULL});
For example:
CREATE TABLE EMPLOYEE(
ID NUMBER NOT NULL
, LASTNAME VARCHAR2(200) NOT NULL
, FIRSTNAME VARCHAR2(100) NULL
, SALARY NUMBER(9,2)
);
You can enhance the basic statement with all kind of features. For example:
Add primary key to table
, CONSTRAINT CONSTRAINT_NAME PRIMARY KEY (KOL_NAME) {USING INDEX TABLESPACE ts_name}
for example:
CREATE TABLE EMPLOYEE(
ID NUMBER NOT NULL
, ...
, constraint emp_pk primary key (ID)
);
Add check constraint to column:
, SALARY NUMBER(9,2) CHECK (SALARY>0 AND SALARY<1000000)
Add default value to column
, CREATE_DATE DATE DEFAULT SYSDATE
Create table based on sql
You can create a table based on the result of a sql.
For example:
Create table emp_copy as select id,firstname,lastname from employee;
|