Chapter 8
Chapter 8
DATA DEFINATION
LANGUAGE
Objectives
Object Description
Table Basic unit of storage; composed of rows
and columns
View Logically represents subsets of data from
one or more tables
Sequence Generates primary key values
Index Improves the performance of some queries
Synonym Gives alternative names to objects
Naming Conventions
• You specify:
• Table name
• Column name, column datatype, and column
size
Referencing Another User’s
Tables
• Tables belonging to other users are not
in the user’s schema.
• You should use the owner’s name as a
prefix to the table.
The DEFAULT Option
• Specify a default value for a column during
an insert.
•… hiredate DATE DEFAULT SYSDATE, …
• User Tables
• Collection of tables created and maintained
by the user
• Contain user information
• Data Dictionary
• Collection of tables created and maintained
by the Oracle server
• Contain database information
Querying the Data Dictionary
• Describe tables owned by the user.
SQL> SELECT *
2 FROM user_tables;
DEPT30
EMPNO ENAME ANNSAL HIREDATE JOB
------ ---------- --------
7698 BLAKE 34200 01-MAY-81
7654 MARTIN 15000 28-SEP-81
7499 ALLEN 19200 20-FEB-81
7844 TURNER 18000 08-SEP-81
...
Adding a Column
• You use the ADD clause to add columns.
SQL> ALTER TABLE dept30
2 ADD (job VARCHAR2(9));
Table altered.
CONSTRAINT_NAME C SEARCH_CONDITION
------------------------ - -------------------------
SYS_C00674 C EMPNO IS NOT NULL
SYS_C00675 C DEPTNO IS NOT NULL
EMP_EMPNO_PK P
...
Viewing the Columns
Associated with Constraints
• View the columns associated with the
constraint names in the
USER_CONS_COLUMNS view.
SQL> SELECT constraint_name, column_name
2 FROM user_cons_columns
3 WHERE table_name = 'EMP';
CONSTRAINT_NAME COLUMN_NAME
------------------------- ----------------------
EMP_DEPTNO_FK DEPTNO
EMP_EMPNO_PK EMPNO
EMP_MGR_FK MGR
SYS_C00674 EMPNO
SYS_C00675 DEPTNO
Dropping a Table