CREATE
(i) Creating a New table.
CREATE TABLE <table name>
(
<column_name> datatype [size],
<column_name> datatype [size],
--
);
(ii) Creating a New table from an existing table.
CREATE TABLE <table_name>
AS
SELECT * or <column_name(s)> FROM <table_name>;
ex 1:
table name: EMP
columns: EMPNO NUMBER + PRIMARY KEY
ENAME VARCHAR + NOT NULL
SALARY NUMBER + >3000
DEPTNO NUMBER
CREATE TABLE EMP
(
EMPNO NUMBER(4) PRIMARY KEY,
ENAME VARCHAR2(20) NOT NULL,
SALARY NUMBER(7,2) CHECK(SALARY > 3000),
DEPTNO NUMBER(4)
);
ex 2:
table name: EMP
target table name: EMP_T
columns: EMPNO NUMBER
DEPTNO NUMBER
CREATE TABLE EMP_T
AS
SELECT EMPNO, DEPTNO FROM EMP;
No comments:
Post a Comment