Using DDL Statements To Create and Manage Tables
Using DDL Statements To Create and Manage Tables
Using DDL Statements To Create and Manage Tables
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
DATABASE OBJECTS
Object Description
Table Basic unit of storage; composed of rows
View Logically represents subsets of data from one or
more tables
Sequence Generates numeric values
Index Improves the performance of some queries
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
CREATE TABLE STATEMENT
You must have:
CREATE TABLE privilege
A storage area
USERA USERB
SELECT * SELECT *
FROM userB.employees; FROM userA.employees;
DEFAULT OPTION
Specify a default value for a column during an insert.
DESCRIBE dept
LESSON AGENDA
Database objects
Naming rules
CREATE TABLE statement:
Access another user’s tables
DEFAULT option
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
DATA TYPES
Data Type Description
VARCHAR2(size) Variable-length character data
CHAR(size) Fixed-length character data
NUMBER(p,s) Variable-length numeric data
DATE Date and time values
LONG Variable-length character data (up to 2 GB)
CLOB Character data (up to 4 GB)
RAW and LONG Raw binary data
RAW
BLOB Binary data (up to 4 GB)
BFILE Binary data stored in an external file (up to 4 GB)
ROWID A base-64 number system representing the unique
address of a row in its table
DATETIME DATA TYPES
You can use several datetime data types:
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
INCLUDING CONSTRAINTS
Constraints enforce rules at the table level.
Constraints prevent the deletion of a table if there
are dependencies.
The following constraint types are valid:
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
CONSTRAINT GUIDELINES
You can name a constraint, or the Oracle server generates a name
by using the SYS_Cn format.
Create a constraint at either of the following times:
At the same time as the creation of the table
After the creation of the table
…
NOT NULL constraint Absence of NOT NULL
(Primary Key enforces NOT NULL constraint (Any row can
NOT NULL constraint.) constraint contain a null value for
this column.)
UNIQUE CONSTRAINT
UNIQUE constraint
EMPLOYEES
…
INSERT INTO
Allowed
Not allowed:
already exists
UNIQUE CONSTRAINT
Defined at either the table level or the column level:
Not allowed
(50 already exists)
KEY CONSTRAINT
FOREIGNDEPARTMENTS
PRIMARY
KEY
…
EMPLOYEES
FOREIGN
KEY
…
INSERT INTO Not allowed
(9 does not
exist)
Allowed
FOREIGN KEY CONSTRAINT
Defined at either the table level or the column level:
UPDATE employees
SET department_id = 55
WHERE department_id = 110;
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
CREATING A TABLE
USING A SUBQUERY
Create a table and insert rows by combining the CREATE TABLE
statement and the AS subquery option.
CREATE TABLE table
[(column, column...)]
AS subquery;
Match the number of specified columns to the number of
subquery columns.
Define columns with column names and default values.
CREATING A TABLE
USING A SUBQUERY
DESCRIBE dept80
LESSON AGENDA
Database objects
Naming rules
CREATE TABLE statement:
Access another user’s tables
DEFAULT option
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
ALTER TABLE STATEMENT
Use the ALTER TABLE statement to:
Add a new column
Modify an existing column definition
Define a default value for the new column
Drop a column
Rename a column
Change table to read-only status
READ-ONLY TABLES
Use the ALTER TABLE syntax to put a table into the read-only
mode:
PreventsDDL or DML changes during table maintenance
Change it back into read/write mode
Data types
Overview of constraints: NOT NULL, PRIMARY KEY, FOREIGN
KEY, CHECK constraints
Creating a table using a subquery
ALTER TABLE
Read-only tables
DROP TABLE statement
DROPPING A TABLE
Moves a table to the recycle bin
Removes the table and all its data entirely if the PURGE clause is
specified
Invalidates dependent objects and removes object privileges on
the table