2.1.2 Data Definition Language

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 23

DATA DEFINITION LANGUAGE

DATA DEFINITION LANGUAGE


Naming Rules
DATA DEFINITION LANGUAGE
DATA DEFINITION LANGUAGE
Default Option
DATA DEFINITION LANGUAGE
Creating Table

Conformation Of Created table


DATA DEFINITION LANGUAGE
Kinds Of Tables In A Data Base
DATA DEFINITION LANGUAGE
Viewing Info from Dictionary Tables
DATA DEFINITION LANGUAGE
Data Types:
DATA DEFINITION LANGUAGE
Creating Table Using Subquery
Syntax

SQL> CREATE TABLE dept1


AS
SELECT * FROM dept;
dept
DATA DEFINITION LANGUAGE
Creating Table Using Subquery (Selective Columns)

SQL> CREATE TABLE emp1


AS
SELECT ename, job, sal
FROM emp;
emp
DATA DEFINITION LANGUAGE
Using Alter Table Statement
DATA DEFINITION LANGUAGE
Using Alter Table Statement
Adding a New Column
Syntax:

SQL> ALTER TABLE EMP1


ADD dname varchar2(15) default Hyd-Bad;
DATA DEFINITION LANGUAGE
Using Alter Table Statement
Modifying a Column

Syntax:

SQL> ALTER TABLE EMP1


MODIFY dname varchar2(20) default Hyd-Bad;
DATA DEFINITION LANGUAGE
Using Alter Table Statement
Modifying a Column
Syntax:

SQL> ALTER TABLE EMP1


DROP COLUMN dname;
DATA DEFINITION LANGUAGE
SET UNUSED option
Syntax:
DATA DEFINITION LANGUAGE
SET UNUSED option
SQL> ALTER TABLE EMP1
SET UNUSED COLUMN comm;

SQL> ALTER TABLE EMP1


SET UNUSED (empno,mgr);
DATA DEFINITION LANGUAGE
Viewing Info from Dictionary Tables

SQL> SELECT * FROM USER_UNUSED_COL_TABS;


DATA DEFINITION LANGUAGE
DROPING A Table

SQL> DROP TABLE emp1;


DATA DEFINITION LANGUAGE
Changing Name Of An Object:

SQL>
DATA DEFINITION LANGUAGE
TRUNCATING A Table:
DATA DEFINITION LANGUAGE
Adding COMMENTS To A Table:

SQL> COMMENT ON TABLE emp


IS Employees information;

SQL> COMMENT ON COLUMN emp.mgr


IS Employees Manager ID
DATA DEFINITION LANGUAGE
Data Dictionary Views:
DATA DEFINITION LANGUAGE
Viewing Info from Dictionary Tables

SQL> SELECT * FROM USER_COL_COMMENTS


WHERE TABLE_NAME=EMP1;

You might also like