L8-2-S1 Misc Topics © M.E. Fayad SJSU -- CmpE Database Design Dr. M.E. Fayad, Professor Computer Engineering Department, Room #283I College of Engineering San José State University One Washington Square San José, CA
L8-2-S2 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad 2 Lesson 08-2: Misc. Topics in DB
L8-2-S3 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad Lesson Objectives 3 Understand DB Terminology Explain Relation Properties Understand how to Identify Candidate, Primary, Alternate, and Foreign Keys Understand Entity Integrity and Referential Integrity
L8-2-S4 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad External Level View Level -- Users’ views of the db. Conceptual Level Logical View & Constraints View Internal Level Physical View or Computer’s view of the db. 4 Terminology: ANSI-SPARC Database Architecture
L8-2-S5 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad A Relation is a table with columns & Rows. An attribute is a named column of a relation. A domain is the set of allowable values for one or more attributes. A tuple is a row of a relation. The degree of a relation is the number of attributes it contains. 5 More Terminology
L8-2-S6 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad 6 Example Branch branchNo street city postCode B Deer Rd London SW1 4EH B Post St Aberdeen AB2 3SU B S. Main St Glasgow GI1 9QX B Mo Ave Bristol BS9 1NX B Clover Dr London NW5 6EU staffNobranchNo B005 B007 B003 B004 B005 Staff Primary KeyForeign Key
L8-2-S7 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad A Relation Schema – A named relation defined by a set of attribute and domain name pairs where: R (A1:d1, A2:d2, …., An:dn) A Database Schema – A set of relation schema each with a distinct name. R = (R1, R2, ….., Rn) 7 More Terminology
L8-2-S8 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad A relation has a name that is distinct from all other relation names within the same db. Each cell of the relation contains exactly one atomic (single) value. Each attribute has a distinct name. The values of an attribute are all from the same domain. 8 Properties of Relations (1)
L8-2-S9 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad Each tuple is distinct, there are no duplicate tuples. The order of attributes has no significance. The order of tuples has no significance, 9 Properties of Relations (2)
L8-2-S10 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad Superkey – An attribute, or set of attributes, that uniquely identifies a tuple within a relation. Candidate key – A Superkey, such that no proper subset is superkey within the relation. A candidate key, k, for a relation R has two properties: 1)Uniqueness: In each tuple of R, the value of k uniquely identify the tuple. 2)Irreducibility – no proper subset of k has the uniqueness property 10 Relational Keys (1)
L8-2-S11 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad They may be several candidate keys for a relation. Composite key – A key consists of more than one attribute. Exampes: 1)Do you think “city” in Branch relation is a candidate key? The answer is no. Why? Because London has two branch offices, therefore, the attribute “city” cannot be a candidate key. 2)Is “branchNo” a candidate key? Yes, Why? By Examining “branchNo”, each branch office has a unique branchNo, 3)Is postcode is a candidate key? Yes.. Why? 11 Relational Keys (2)
L8-2-S12 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad Primary key: The candidate key that is selected to identify tuples uniquely within the relation Alternate keys – The Candidate keys that are not selected to be the primary key. Exampes: 1)In the Branch Relation, we can choose branchNo as the primary key and 2)Postcode as an alternate key. 12 Relational Keys (3)
L8-2-S13 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad 13 Relational Keys (4) –Foreign key: An attribute, or a set of attributes, with one relation that matches the candidate key of some (possibly the same) relation. –branchNo appeared in two relations: Branch and Saff relations –branchNo is a primary key in Branch relation and it is a foreign key in the Staff relation.
L8-2-S14 Misc Topics © M.E. Fayad SJSU – CmpE --- M.E. Fayad T/F 1.Each cell of the relation contains exactly on atomic (single) value. 2.Primary key is the candidate key that is selected to identify tuples uniquely within the database. 3.Foreign key is an attribute or a set of attributes within on relation that matches the candidate key of some relation. 4.The degree of a relation is the number of tuples it contains. 14 Discussion Questions