You are on page 1of 3

1.

CREATE TABLE Course (


dept CHAR(2) NOT NULL,
cnum INTEGER NOT NULL,
PRIMARY KEY(cnum)
FOREIGN KEY (dept) REFERENCES Department(dept)
ON DELETE CASCADE ON UPDATE SET NULL
2. Relational Algebra operators
a. Select operator
i. filters out rows in relation
ii. Notation: C (R)
1. C bools (<, >, <>, =, ^, V, )
b. project operator
i. filters out columns in a relation
c. R x S - Cartesian Product
i. combines relations
d. - Natural Join
i. Cartesian product that enforce equality on common attributes
e. C Theta Join
i. Cartesian product enforcing condition C
f. Rename operator
i. Notation S(R) Renames R to S
g.
- Union operator
i. combines relations with same schema
h. - - difference operator
i. - intersect operator
i. filters out uncommon rows
j. / - division operator
3. SQL statements
a. SELECT attributes, aggregates
FROM relations
WHERE conditions
GROUP BY attributes
HAVING conditions on aggregates
ORDER BY attributes, aggregates
b. INTERSECT, UNION, EXCEPT
i. To keep duplicates use UNION ALL, etc
c. Set membership (IN, NOT IN)
i. Returns true if tuple is within the set
d. Set comparison (> ALL, < SOME, )
e. EXISTS (SUBQUERY)
i. returns true if SUBQUERY returns at least 1 tuple
f. Subqueries in FROM clause must be renamed
g. Aggregates
i. SUM, AVG, COUNT
ii. GROUP BY
iii. HAVING
h. Outer Join
i. R [LEFT|RIGHT|FULL] OUTER JOIN S
i. ORDER BY field [DESC|ASC]
j. INSERT INTO Relations Tuples
k. DELETE FROM R WHERE Condition
l. Checking Null

4.

5.

6.

7.

i. IS NULL, IS NOT NULL


m. UPDATE table SET a1 = v1, WHERE cond
n. NULL rules:
i. aggregates are computed ignoring null except COUNT(*)
Database Integrity
a. Key Constraints
b. Referential constraints (FOREIGN KEY (x,y,z) REFERENCES T2(a,b,c))
i. foreign key must be unique
ii. Check when insert/update
iii. ON DELETE/UPDATE SET NULL/SET DEFAULT/CASCADE
c. Check Constraints
i. CHECK (C)
d. Triggers
i. CREATE TRIGGER name [BEFORE|AFTER] [INSERT|UPDATE|DELETE]
ON table REFERENCING NEW [ROW|TABLE] AS newname FOR EACH
[ROW|STATEMENT] WHEN (cond) BEGIN statement END
Views and Authorization
a. VIEWS
i. CREATE VIEW name AS (SELECT statement)
ii. only updatable if only one table in FROM clause
iii. No aggregates allowed if updatable
iv. WITH CHECK OPTION
b. Authorization
i. GRANT [SELECT|UPDATE|DELETE|INSERT|ALL PRIVILEGES] ON
table TO [user|PUBLIC] [WITH GRANT OPTION]
ii. REVOKE [SELECT|UPDATE|DELETE|INSERT| ALL PRIVILEGES] ON
table FROM [user|PUBLIC] [CASCADE|RESTRICT]
iii. To create view, user needs select privileges on all base tables
iv. To grant privileges, user has to have GRANT OPTION privilege on base
tables
Disks and files
a. Access time = seek time + rotational delay + transfer time
b. burst transfer rate = (rpm/60)* (sectors/track)*(bytes/sector)
c. variable length tuples use slotted page
Index
a. Primary (clustering) index are sequential and ordered
b. Dense index has pair for every record while sparse doesnt
c. B+ Tree

8. ER Model
a. Entity set: rectangle
i. table with all attributes
b. Attributes: ellipsis
c. Key: underlined
d. Relation diamond
i. table with keys from linked ES and its own attributes
e. Cardinality
i. arrow at most one
ii. regular line unlimited
iii. double line total participation (at least one)
f. Subclasses triangle
i. inherits all attributes of super class
g. Weak entity set double rectangle and double diamond
i. sets without unique keys
ii. gets keys from owner
9. Normalization Theory
a. Lossless join is possible when both table contains a key for one of the tables
10. Join Algorithm and cost models
a. Nested loop join = bR + ceiling(bR/(m-2))*bS
b. Index Join = bR + |R| * (C+J)
i. Create index, For each r in R, index lookup and print matching tuples
ii. R = relation, C = average lookup cost, J = matching tuples in R per S tuple
c. Sort Merge = 2*bR (ceiling(logM-1(bR/M))+1) + 2*bS (ceiling(logM-1(bS/M))+1) + bR
+ bS
d. Hash Join = 2*( bR + bS) * ceiling(logM-1(bR/(M-2)))+( bR + bS)
11. Transactions
a. ACID Atomicity, Consistency, Isolation, Durability
i. 2-phase locking guarantees C,I
ii. logs guarantee A,D

You might also like