<<

COSC 304 - Dr. Ramon Lawrence

COSC 304 History Introduction to Systems The relational model was proposed by E. F. Codd in 1970.

Relational Model and Algebra One of the first systems, System R, developed at IBM led to several important breakthroughs: the first version of SQL various commercial products such as Oracle and DB2 Dr. Ramon Lawrence extensive research on , transaction University of British Columbia Okanagan management, and query processing and optimization [email protected] Commercial implementations (RDBMSs) appeared in the late 1970s and early 1980s. Currently, the relational model is the foundation of the majority of commercial database systems.

Page 2

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Relational Model Definitions Example A relation is a with columns and rows. relation An attribute is a named of a relation. attributes A tuple is a of a relation. A domain is a set of allowable values for one or more attributes. tuples The degree of a relation is the number of attributes it contains. The cardinality of a relation is the number of tuples it contains. A relational database is a collection of normalized relations with distinct relation names. The intension of a relation is the structure of the relation Degree = 7 Domain of Unit including its domains. Cardinality = 77 Price is currency. The extension of a relation is the set of tuples currently in the relation. Page 3 Page 4

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Definition Matching Question Cardinality and Degree Question Question: Given the three definitions, select the ordering that Question: A database table has 10 rows and 5 columns. contains their related definitions. Select one true statement.

1) relation A) The table's degree is 50. 2) tuple 3) attribute B) The table's cardinality is 5.

A) column, row, table C) The table's degree is 10. B) row, column, table C) table, row, column D) The table's cardinality is 10. D) table, column, row

Page 5 Page 6 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Relation Practice Questions Relational Model Formal Definition The relational model may be visualized as tables and fields, but it is formally defined in terms of sets and .

A relation schema R with attributes A = is denoted R (A1, A2, …, An) where each Ai is an attribute name that ranges over a domain Di denoted dom(Ai).

Example: Product (id, name, supplierId, categoryId, price) 1) What is the name of the relation? R = Product (relation name) 2) What is the cardinality of the relation? Set A = {id, name, supplierId, categoryId, price} 3) What is the degree of the relation? dom(price) is set of all possible positive currency values 4) What is the domain of order date? What is the domain of dom(name) is set of all possible strings that represent people's order id? names 5) What is larger the size of the intension or extension? Page 7 Page 8

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Relation Schemas and Instances Cartesian Product (review)

A relation schema is a definition of a single relation. The Cartesian product written as D1  D2 is a set operation The relation schema is the intension of the relation. that takes two sets D1 and D2 and returns the set of all ordered pairs such that the first element is a member of D1 and the A relational database schema is a set of relation schemas second element is a member of D . (modeling a particular domain). 2 Example:

D1 = {1,2,3} A relation instance denoted r(R) over a relation schema R(A1, D2 = {A,B} A2, …, An) is a set of n-tuples where each di is  an element of dom(Ai) or is . D1  D2 = {(1,A), (2,A), (3,A), (1,B), (2,B), (3,B)} The relation instance is the extension of the relation. Practice Questions:

A value of null represents a missing or unknown value. 1) Compute D2  D1.

2) Compute D2  D2. 3) If |D| denotes the number of elements in set D, how many elements are there in D1  D2 in general.

Page 9 What is the cardinality of D1  D2  D1  D1? A) 27 B) 36 C) 54 Page 10

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Relation Instance Properties of Relations A relation instance r(R) can also be defined as a subset of the A relation has several properties: Cartesian product of the domains of all attributes in the relation 1) Each relation name is unique. schema. That is, No two relations have the same name. r(R)  dom(A1) dom(A2) …  dom(An) 2) Each cell of the relation (value of a domain) contains exactly one atomic (single) value. Example: 3) Each attribute of a relation has a distinct name. R = Person(id, firstName, lastName) 4) The values of an attribute are all from the same domain. dom(id) = {1,2}, dom(firstName) = {Joe, Steve} 5) Each tuple is distinct. There are no duplicate tuples. dom(lastName) = {Jones, Perry} This is because relations are sets. In SQL, relations are bags. dom(id) dom(firstName)  dom(lastName) = 6) The order of attributes is not really important. { (1,Joe,Jones), (1,Joe,Perry), (1,Steve,Jones), (1,Steve,Perry), Note that this is different that a mathematical relation and our definitions (2,Joe,Jones), (2,Joe,Perry), (2,Steve,Jones), (2,Steve,Perry)} which specify an ordered tuple. The reason is that the attribute names represent the domain and can be reordered. Assume our DB stores people Joe Jones and Steve Perry, then 7) The order of tuples has no significance. r(R) = { (1,Joe, Jones), (2,Steve,Perry)}. Page 11 Page 12 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Relational Keys Keys and Superkeys Question Keys are used to uniquely identify a tuple in a relation. Question: True or false: A key is always a . Note that keys apply to the relational schema not to the relational instance. That is, looking at the current data cannot tell you for sure if the set of attributes is a key. A) true A superkey is a set of attributes that uniquely identifies a tuple in a relation. B) false A (candidate) key is a minimal set of attributes that uniquely identifies a tuple in a relation. There may be more than one for a relation. A is the candidate key designated as the distinguishing key of a relation. A is a set of attributes in one relation referring to the primary key of another relation. Foreign keys allow to be enforced. Note: FK can refer to its own relation. Page 13 Page 14

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Keys and Superkeys Question (2) Keys and Superkeys Question (3) Question: True or false: It is possible to have more than one Question: True or false: It is possible to always determine if a key for a table and the keys may have different numbers of field is a key by looking at the data in the table. attributes. A) true A) true B) false B) false

Page 15 Page 16

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Example Relations Example Relation Instances Employee-Project Database: Emp Relation WorksOn Relation Employees have a unique number, name, title, and salary. Projects have a unique number, name, and budget. An employee may work on multiple projects and a project may have multiple employees. An employee on a project has a particular responsibility and duration on the project. Relations: Emp (eno, ename, title, salary) Proj Relation Proj (pno, pname, budget) WorksOn (eno, pno, resp, dur) Questions: 1) Is ename a key for emp? Underlined attributes denote keys. 2) Is eno a key for WorksOn? Page 17 3) List all the superkeys for WorksOn. Page 18 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Practice Questions Relational Integrity Consider a relation storing driver information including: Integrity rules are used to insure the data is accurate. SSN, name, license plate number and state (unique together) Constraints are rules or restrictions that apply to the database and limit the data values it may store. Driver Relation Types of constraints: Domain constraint - Every value for an attribute must be an element of the attribute's domain or be null. null represents a value that is currently unknown or not applicable. null is not the same as zero or an empty string. Entity integrity constraint - In a base relation, no attribute of a Questions: Assumptions: primary key can be null. 1) List the candidate keys for the relation. 1) A person has only one license plate. Referential integrity constraint - If a foreign key exists in a 2) Pick a primary key for the relation. 2) A license plate uniquely relation, then the foreign key value must match a primary key 3) Is name a candidate key for Person? identifies a person. value of a tuple in the referenced relation or be null. 4) List all the superkeys for Person. Page 19 Page 20

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Foreign Keys Example Foreign Keys Example (2) Emp Relation WorksOn Relation Proj Relation WorksOn.eno is FK to Emp.eno

WorksOn.pno is FK to Proj.pno

Proj.dno is Proj Relation FK to Dept.dno Department Relation

Page 21 Page 22

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Integrity Constraints Question Entity Integrity Constraint Question Question: What constraint says that a primary key field cannot Question: A primary key has three fields. Only one field is be null? null. Is the entity integrity constraint violated?

A) domain constraint A) Yes

B) referential integrity constraint B) No

C) entity integrity constraint

Page 23 Page 24 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Referential Integrity Constraint Question Integrity Questions Question: A foreign key has a null value in the table that Emp Relation WorksOn Relation contains the foreign key fields. Is the referential integrity constraint violated?

A) Yes

B) No

Proj Relation

Question: How many rows have violations of integrity constraints? A) 8 B) 9 C) 10 D) 11 E) 12 Page 25 Page 26

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

General Constraints There are more general constraints that some DBMSs can A is used to update and retrieve data that is enforce. These constraints are often called enterprise stored in a data model. constraints or semantic integrity constraints. Relational algebra is a set of relational operations for retrieving data. Examples: Just like algebra with numbers, relational algebra consists of operands (which are relations) and a set of operators. An employee cannot work on more than 2 projects. An employee cannot make more money than their manager. Every relational operator takes as input one or more relations and produces a relation as output. An employee must be assigned to at least one project. Closure property - input is relations, output is relations Unary operations - operate on one relation Ensuring the database follows these constraints is usually achieved using triggers. Binary operations - have two relations as input A sequence of relational algebra operators is called a relational algebra expression. Page 27 Page 28

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Relational Algebra Operators Selection Operation Relational Operators: The selection operation is a unary operation that takes in a Selection  relation as input and returns a new relation as output that contains a subset of the tuples of the input relation. Projection  That is, the output relation has the same number of columns as Cartesian product  the input relation, but may have less rows. Join Union  To determine which tuples are in the output, the selection Difference - operation has a specified condition, called a predicate, that Intersection  tuples must satisfy to be in the output. The predicate is similar to a condition in an if statement. Note that relational algebra is the foundation of ALL relational database systems. SQL gets translated into relational algebra.

Page 29 Page 30 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Selection Operation Formal Definition Selection Example Emp Relation The selection operation on relation R with predicate F is title = 'EE' (Emp) denoted by F(R).

F(R)={t tR and F(t) is true}

salary > 35000 OR title = 'PR' (Emp) where R is a relation, t is a tuple variable F is a formula (predicate) consisting of operands that are constants or attributes comparison operators: <, >, =, , ,  logical operators: AND, OR, NOT

Page 31 Page 32

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Selection Question Selection Question (2) Question: Given this table and the query: Question: Given this table and the query:

salary > 50000 or title='PR'(Emp) salary > 50000 or title='PR'(Emp) How many rows are returned? Emp Relation How many columns are returned? Emp Relation

A) 0 A) 0 B) 1 B) 2 C) 2 C) 3 D) 3 D) 4

Page 33 Page 34

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Selection Questions Projection Operation

WorksOn Relation The projection operation is a unary operation that takes in a Write the relational algebra expression that: relation as input and returns a new relation as output that 1) Returns all rows with an employee working contains a subset of the attributes of the input relation and all on project P2. non-duplicate tuples. 2) Returns all rows with an employee who is The output relation has the same number of tuples as the input working as a manager on a project. relation unless removing the attributes caused duplicates to be 3) Returns all rows with an employee working present. as a manager for more than 40 months. Question: When are we guaranteed to never have duplicates Show the resulting relation for each case. when performing a projection operation?

Besides the relation, the projection operation takes as input the names of the attributes that are to be in the output relation.

Page 35 Page 36 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Projection Operation Formal Definition Projection Example

The projection operation on relation R with output attributes Emp Relation  eno,ename (Emp) A ,…,A is denoted by  (R). 1 m A1,…,Am

 (R)={t[A ,…, A ] tR} A1,…,Am 1 m

where R is a relation, t is a tuple variable

{A1,…,Am} is a subset of the attributes of R over which the projection will be performed.  title (Emp) Order of A1,…, Am is significant in the result.

Cardinality of A ,…,A (R) is not necessarily the same as R because of duplicate removal.1 m

Page 37 Page 38

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Projection Question Projection Questions

Question: Given this table and the query: WorksOn Relation

 title (Emp) Write the relational algebra expression that: Emp Relation 1) Returns only attributes resp and dur. How many rows are returned? 2) Returns only eno. 3) Returns only pno. A) 0 Show the resulting relation for each case. B) 2 C) 4 D) 8

Page 39 Page 40

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Union Union Example

Union is a binary operation that takes two relations R and S as Emp input and produces an output relation that includes all tuples that are either in R or in S or in both R and S. Duplicate tuples are eliminated.

 (Emp)   (WorksOn) General form: eno eno R  S = {t tR or tS} where R, S are relations, t is a tuple variable. R and S must be WorksOn union-compatible. To be union-compatible means: 1) Both relations have same number of attributes.

2) Each attribute pair, Ri and Si, have compatible data types for all attribute indexes i. Note that attributes do not need to have the same name. Result has attribute names of first relation. Page 41 Page 42 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Set Difference Set Difference Example

Set difference is a binary operation that takes two relations R Emp Relation WorksOn Relation and S as input and produces an output relation that contains all the tuples of R that are not in S.

General form: R – S = {t tR and tS} where R and S are relations, t is a tuple variable.

Note that: R – S  S – R eno(Emp)  eno(WorksOn) R and S must be union compatible. Question: What is the meaning of this query?

Question: What is eno(WorksOn) eno(Emp)? Page 43 Page 44

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Intersection Intersection Example Intersection is a binary operation that takes two relations R Emp and S as input and produces an output relation which contains all tuples that are in both R and S.

General form: eno(Emp)  eno(WorksOn) R  S = {t tR and tS} where R, S are relations, t is a tuple variable. R and S must be union-compatible. WorksOn

Note that R  S = R –(R – S) = S –(S – R).

Page 45 Page 46

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence Set Operations Union-compatible Question Cartesian Product

Question: Two tables have the same number of fields in the The Cartesian product of two relations R (of degree k1) and S same order with the same types, but the names of some fields (of degree k2) is: are different. True or false: The two tables are union- compatible. R  S = {t  t [A ,…,A ]R and t [A ,…,A ]S} 1 k1 k1+1 k1+k2 A) true The result of R  S is a relation of degree (k1 + k2) and consists of all (k1 + k2)-tuples where each tuple is a concatenation of one B) false tuple of R with one tuple of S.

The cardinality of R  S is |R| * |S|.

The Cartesian product is also known as cross product. Page 47 Page 48 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Cartesian Product Example Cartesian Product Question Emp Relation Emp  Proj Question: R is a relation with 10 rows and 5 columns. S is a relation with 8 rows and 3 columns. What is the degree and cardinality of the Cartesian product?

A) degree = 8, cardinality = 80 Proj Relation B) degree = 80, cardinality = 8

C) degree = 15, cardinality = 80

D) degree = 8, cardinality = 18

Page 49 Page 50

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

 -Join  -Join Example

Theta () is a derivative of the Cartesian product. Instead WorksOn Relation WorksOn dur*10000 > budget Proj of taking all combinations of tuples from R and S, we only take a subset of those tuples that match a given condition F:

R S = {t  t [A ,…,A ]R and t [A ,…,A ]S F 1 k1 k1+1 k1+k2 and F(t) is true} where R, S are relations, t is a tuple variable Proj Relation F(t) is a formula defined as that of selection.

Note that R F S = F(R  S).

Page 51 Page 52

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Types of Joins Equijoin Example

The -Join is a general join in that it allows any expression in WorksOn Relation WorksOn WorksOn.pno = Proj.pno Proj the condition F. However, there are more specialized joins that are frequently used.

A equijoin only contains the equality operator (=) in formula F.

e.g. WorksOn WorksOn.pno = Proj.pno Proj

A natural join over two relations R and S denoted by R S is the equijoin of R and S over a set of attributes common to both Proj Relation R and S. What is the meaning of this join? It removes the “extra copies” of the join attributes. The attributes must have the same name in both relations.

Page 53 Page 54 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Natural join Example Join Practice Questions WorksOn Relation WorksOn Proj Emp Relation WorksOn Relation

Proj Relation Proj Relation Natural join is performed by comparing pno in both relations. Compute the following joins (counts only):

1) Emp ⨝title='EE' and budget > 400000 Proj 2) Emp ⨝ WorksOn 3) Emp ⨝ WorksOn ⨝ Proj Page 55 4) Proj1 ⨝ Proj1.budget > Proj2.budget Proj2 Page 56

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Outer Joins Right Outer Join Example

Outer joins are used in cases where performing a join "loses" WorksOn Relation WorksOn WorksOn.pno = Proj.pno Proj some tuples of the relations. These are called dangling tuples. There are three types of outer joins: 1) Left outer join - RS- The output contains all tuples of R that match with tuples of S. If there is a tuple in R that matches with no tuple in S, the tuple is included in the final result and is padded with nulls for the attributes of S. 2) Right outer join - RS- The output contains all tuples of S that match with tuples of R. If there is a tuple in S that matches with no tuple in R, the tuple is included in the final Proj Relation result and is padded with nulls for the attributes of R. 3) Full outer join - RS- All tuples of R and S are included in the result whether or not they have a matching tuple in the other relation. Page 57 Page 58

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Outer Join Question Semi-Join and Anti-Join

Question: Given this table and the query: WorksOn Relation A semi-join between tables returns rows from the first table where one or more matches are found in the second table. WorksOn Proj WorksOn.pno = Proj.pno Semi-joins are used in EXISTS and IN constructs in SQL. How many rows are returned? An anti-join between two tables returns rows from the first table where no matches are found in the second table. A) 10 Anti-joins are used with NOT EXISTS, NOT IN, and FOR ALL. B) 9 Proj Relation Anti-join is the complement of semi-join: R S = R - R ⋉ S C) 8 D) 7

Page 59 Page 60 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Semi-Join Example Anti-Join Example

WorksOn Relation Proj ⋉Proj.pno = WorksOn.pno WorksOn WorksOn Relation Proj ⊳ Proj.pno = WorksOn.pno WorksOn

Proj Relation Proj Relation

Page 61 Page 62

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Aside: Division Operator Combining Operations There is also a division operator used when you want to Relational algebra operations can be combined in one determine if all combinations of a relationship are present. expression by nesting them:  E.g. Return the list of employees who work on all the projects eno,pno,durename='J. Doe' (Emp) dur>16 (WorksOn)) that 'John Smith' works on. Return the eno, pno, and duration for employee 'J. Doe' when he has worked on a project for more than 16 months. The division operator is not a base operator and is not frequently used, so we will not spend any time on it. Operations also can be combined by using temporary relation

Note that R ÷ S = R-S(R)R-S ((R-S (R)S)R). variables to hold intermediate results. We will use the assignment operator  for indicating that the result of an operation is assigned to a temporary relation.

empdoe ename='J. Doe' (Emp) wodur dur>16 (WorksOn) empwo  empdoe wodur Page 63 result  eno,pno,dur (empwo) Page 64

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Rename Operation Operator Precedence Renaming can be applied when assigning a result: Just like mathematical operators, the relational operators have precedence.

result(EmployeeNum, ProjectNum, Duration)  eno,pno,dur (empwo) The precedence of operators from highest to lowest is:

unary operators -  Or by using the rename operator  (rho): Cartesian product and joins - X, ⨝ , division intersection result(EmployeeName, ProjectNum, Duration)(empwo) union and set difference Parentheses can be used to changed the order of operations. It is a good idea to always use parentheses around the argument for both unary and binary operators.

Page 65 Page 66 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence Complete Set of Relational Algebra Operators Relational Algebra Query Examples It has been shown that the relational operators {, , , -} Consider the database schema form a complete set of operators. Emp (eno, ename, title, salary) That is, any of the other operators can be derived from a Proj (pno, pname, budget) combination of these 5 basic operators. WorksOn (eno, pno, resp, dur)

Examples: Queries: Intersection - R S  R  S  ((R - S)  (S - R)) List the names of all employees. We have also seen how a join is a combination of a Cartesian  (Emp) product followed by a selection. ename

Find the names of projects with budgets over $100,000.

pname(budget>100000 (Proj))

Page 67 Page 68

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Practice Questions Practice Questions (2)

Relational database schema: branch (bname, address, city, assets) branch (bname, address, city, assets) customer (cname, street, city) customer (cname, street, city) deposit (accnum, cname, bname, balance) deposit (accnum, cname, bname, balance) borrow (accnum, cname, bname, amount) borrow (accnum, cname, bname, amount) 1) Find the names of all branches with assets greater than 1) List the names of all branches of the bank. $2,500,000. 2) List the names of all deposit customers together with their 2) List the name and cities of all customers who have an account numbers. account with balance greater than $2,000. 3) Find all cities where at least one customer lives. 3) List all the cities with at least one customer but without any 4) Find all cities with at least one branch. bank branches. 5) Find all cities with at least one branch or customer. 4) Find the name of all the customers who live in a city with no bank branches. 6) Find all cities that have a branch but no customers who live in that city. Page 69 Page 70

COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Practice Questions (3) Other Relational Algebra Operators

branch (bname, address, city, assets) There are other relational algebra operators that we will not discuss. Most notably, we often need aggregate operations customer (cname, street, city) that compute functions on the data. deposit (accnum, cname, bname, balance) borrow (accnum, cname, bname, amount) For example, given the current operators, we cannot answer 1) Find all the cities that have both customers and bank the query: branches. What is the total amount of deposits at the Kelowna branch? 2) List the customer name and loan and deposit amounts, who have a loan larger than a deposit account at the same branch. 3) Find the name and assets of all branches which have We will see how to answer these queries when we study SQL. deposit customers living in Vancouver. 4) Find all the customers who have both a deposit account and a loan at the branch with name CalgaryCentral. 5) Your own? Page 71 Page 72 COSC 304 - Dr. Ramon Lawrence COSC 304 - Dr. Ramon Lawrence

Conclusion Objectives

The relational model represents data as relations which are Define: relation, attribute, tuple, domain, degree, cardinality, sets of tuples. Each relational schema consists of a set of relational DB, intension, extension attribute names which represent a domain. Define: relation schema, relational database schema, relation instance, null The relational model has several forms of constraints to Perform Cartesian product given two sets. guarantee data integrity including: List the properties of relations. domain, entity integrity and referential integrity constraints Define: superkey, key, candidate key, primary key, foreign key Keys are used to uniquely identify tuples in relations. Define: integrity, constraints, domain constraint, entity integrity constraint, referential integrity constraint Relational algebra is a set of operations for answering queries Given a relation be able to: on data stored in the relational model. identify its cardinality, degree, domains, keys, and superkeys determine if constraints are being violated The 5 basic relational operators are: {, , , -}. By combining relational operators, queries can be answered over the base relations. Page 73 Page 74

COSC 304 - Dr. Ramon Lawrence

Objectives (2)

Define: relational algebra, query language Define and perform all relational algebra operators. List the operators which form the complete set of operators. Show how other operators can be derived from the complete set.

Given a relational schema and instance be able to translate English queries into relational algebra and show the resulting relation.

Page 75