CSC271 Database Systems: Data Definition Language
CSC271 Database Systems: Data Definition Language
CSC271 Database Systems: Data Definition Language
2
Deleting a Database Instance
3
Other DDL Commands
4
Steps in Creating a Table
5
Common Data Types in SQL
6
Create Table Construct
7
Integrity Constraints
8
Domain Integrity Constraints
9
Entity Integrity Constraint
10
Referential Integrity Constraint
11
Referential Integrity Constraint
Ensures that foreign key values of a table must match
primary key values of a related table.
[CONSTRAINT] FOREIGN KEY (col_name,...)
REFERENCES targer_table_name
(target_table_primary_column,...)
Example
create table Student (sid
integer AUTO_INCREMENT, name char (30),
pid integer,Column names could
primary key (id), foreign key (pid)
be different
references Program (pid))
What to do with
tuples of Student
if relevant
Program tuple is
deleted
13
Complete Foreign Key Declaration
pid integer,
primary key (id),
foreign key (pid) references Program (pid) on
delete RESTRICT on update CASCADE )
14
Schema (Pine Valley Furniture
Company)
Referential
integrity
constraints are
drawn via arrows
from dependent
to primary table
15
Drop and Alter Table Constructs
16
Views
17
View Definition
18
View Usage
19
View Types
Dynamic View
A virtual table created dynamically
No data actually stored; data from the base table is
made available to user on request.
Based on SELECT statement on base tables or other
views
Materialized View (Supported in Oracle, for instance)
Copy or replication of data
Data actually stored on the disk
Refreshed periodically (or on every change) to match
the corresponding base table data
20
More on Views
A database cannot contain a base table and a view that
have the same name.
Views must have unique column names with no
duplicates.
By default, the names of the columns retrieved by the
SELECT statement are used for the view column
names.
To define explicit names for the view columns, a list of
comma-separated names should be provided.
create view v (column1, column2, ...) as <query>
21