A collection of one or more relations
Each relation is a table with rows and columns
Students( sid: string, name: string, login: string, age: integer, gpa: real )
CREATE TABLE Students (
sid CHAR(20),
name CHAR(30),
login CHAR(20),
age INTEGER,
gpa REAL
)
INSERT
INTO Students (sid, name, login, age, gpa)
VALUES (53688, 'Smith', 'smith@ee', 18, 3.2)
DELETE
FROM Students S
WHERE S.name = 'Smith'
UPDATE Students S
SET S.age = S.age + 1, S.gpa = S.gpa - 1
WHERE S.sid = 53688
Integrity constraints are specified and enforced
Unique identifier for a record
CREATE TABLE Students (
sid CHAR(20),
name CHAR (30),
login CHAR(20),
age INTEGER,
gpa REAL,
UNIQUE (name, age),
CONSTRAINT StudentsKey PRIMARY KEY (sid)
)
CREATE TABLE Enrolled (
studid CHAR(20),
cid CHAR(20),
grade CHAR(10),
PRIMARY KEY (studid, cid),
FOREIGN KEY (studid) REFERENCES Students
)
Ex: Student must be at least 16 years old
If a command causes violation, it is rejected.
If insert, update causes violation, it is rejected.
What if a Students row is deleted?
CREATE TABLE Enrolled (
studid CHAR(20),
cid CHAR(20),
grade CHAR(10),
PRIMARY KEY (studid, dd),
FOREIGN KEY (studid) REFERENCES Students
ON DELETE CASCADE
ON UPDATE NO ACTION
)
NO ACTION CASCADE SET DEFAULT SET NULL
SET CONSTRAINT ConstntintFoo DEFERRED
SET CONSTRAINT ConstntintFoo IMMEDIATE
CREATE VIEW B-Students (name, sid, course)
AS SELECT S.sname, S.sid, E.cid
FROM Students S, Enrolled E
WHERE S.sid = E.studid AND E.grade = 'B'
Only views that are defined on a single base table using just selection and projection,
with no use of aggregate operations