Académique Documents
Professionnel Documents
Culture Documents
Objectives
Identify the table name and structure
Objectives (cont.)
Mark a column as unused and then delete it at a later
time
Constraints
Restrictions on data values that column can store
Database Table
A database object
Table Design
Table and column names:
Can contain a maximum 30 characters no blank spaces Must begin with a letter Can contain numbers, underscore (_), and number sign
(#) Must be unique No reserved words are allowed
Fixed-point number
Contains specific number of decimal places Column declaration specifies both precision and scale Example:
prod_price NUMBER(5, 2)
Floating-point number
Contains variable number of decimal places Syntax:
columnname NUMBER Example: s_gpa NUMBER
Oracle 11g: SQL
9
function
10
Table Creation
11
Defining Columns
Column definition list must be enclosed in parentheses
12
Virtual Column
13
Data Dictionary
Oracle data dictionary
Consists of tables that contain information about structure
of database When a new database is created, the system creates the data dictionary in a user schema named SYS Users do not directly manipulate with the data dictionary tables Users interact with the database through views
Syntax
SELECT view_columnname1, view_columnname2 FROM
prefix_object;
where view_columnname1, view_columnname2 are names of the columns
in the view you wish to retrieve prefix is the view category (USER, ALL, DBA) Object is the type of the database object you are examining (TABLES, CONSTRAINTS, etc.)
Oracle 11g: SQL
16
17
18
19
CREATE TABLEAS
20
21
22
23
24
25
Unrestricted action
Some specifications of tables can always be modified
Restricted action
Table specifications that can be modified only in certain
situations
26
Modification Guidelines
Column must be as wide as the data it already contains
27
28
29
30
Renaming a Table
RENAMETO is used to rename a table the
old name is no longer valid
31
Truncating a Table
TRUNCATE TABLE command rows are
deleted
32
Deleting a Table
DROP TABLE command table structure
and contents are deleted
33
34
FLASHBACK Command
The FLASHBACK command recovers a
table from the recycle bin
35
36
37
Summary
You create a table with the CREATE TABLE command Each column to be contained in the table must be defined in
terms of the column name, data type, and for certain data types, the width
Summary (cont.)
To delete all the rows in a table, use the TRUNCATE
TABLE command