Cheat Sheet On DataBase Management
Cheat Sheet On DataBase Management
Cheat Sheet On DataBase Management
Super Key a set of >= 1 attributes whose values uniquely determine each entity
Candidate Key a minimal super key w/o redundant attributes
Primary Key one of candidate key
Element
Notes
Relational tables
Attribute
Multi-valued
Both entries are primary key
Derived
No need to include in tables
Composite
No need to include the root of
the composite attribute
**Relationship set table is not
Weak entity set
*(Total many)-to-one
needed
Role
Specialization and
Generalization
Hierarchical structure
Disjoint / overlapping
1.
2.
3.
(Tree rotation)
4.
5.
6.
( E1 E2 ) E 3=( E2 E1 ) E3=E 1 (E 2 E3 )
7.
8.
Notes:
For , , set difference , the number of attributes and the same type
Operator
Description
SQL equivalent
E.g.
RS
S R
NOT IN /EXCEPT
Find the sID and
name of the
RS
Cartesian Product
FROM table1,
employee who
table2
know all the IT
R S
Joining table
skills.
RS
all tuples in col 1 of R
keyword/ joining
Staff
the same table
with alias
R S
SELECT E.name FROM Employee E,
Works_in W
WHERE E.id = W.id AND (W.deid=1 OR
W.deid=3);
SELECT E.name FROM W.deid=1
UNION
SELECT E.name FROM W.deid=3;
Q. Assertion to check
update
CREATE ASSERTION label
Q. Create View
CREATE VIEW title(label) AS();
Q. Find all employee names for which the salary
is unknown
Q. Budget>SOME(Depart em4
SELECT name FROM Employees WHERE salary IS
works)
Q. Find the names of employees who work in at least 2
SELECT D.name FROM Department departments
D
SELECT E.name FROM Employees E
WHERE D.budget > SOME(
WHERE 2 <= (
SELECT D2.budget
SELECT COUNT(W.department_id)
FROM Department D2
FROM Works_in W
WHERE D2.department_id IN(
WHERE W.employee_id=E.employee_id
SELECT W.department_id
);
Q. AUTHORIZATION
FROM Works_in W
WHERE W.employee_id =4GRANT <list> ON <table/view> TO
<user/role list>;
));
CREATE ROLE role;