1 / 60

Review Applications of Database Systems

Review Applications of Database Systems. Theory. Applications of Database Systems. Practice. ER-diagram. Relational databases:. Theory Part. Referential integrity. Relation normalization. ER-diagram. Entity types Strong entity type Weak entity type Relationships

johnstonr
Download Presentation

Review Applications of Database Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ReviewApplications of Database Systems Theory Applications of Database Systems Practice

  2. ER-diagram Relational databases: Theory Part Referential integrity Relation normalization

  3. ER-diagram Entity types Strong entity type Weak entity type Relationships Cardinality constraints: 1:1, 1:M, M:N - relationship Participation constraints: mandatory, optional Attributes atomic attributes composite attributes single-valued, multi-valued attributes derived attributes key, partial key, surrogate key, non-key attribute

  4. Mapping from ER-diagrams onto relational schemas • Create a relation for each strong entity type • Create a relation for each weak entity type • 3. For each binary 1:1 relationship choose an entity and include the • other’s PK in it as an FK • 4. For each binary 1:n relationship, choose the n-side entity and include • an FK with respect to the other entity. • 5. For each binary M:N relationship, create a relation for the relationship • 6. For each multi-valued attribute create a new relation • 7. For each n-ary relationship, create a relation for the relationship

  5. Referential Integrity (i) Consider two relation schemas R1 and R2; • The attributes in FK (foreign key) in R1 have the same domain(s) as the primary key attributes PK (primary key) in R2; the attributes FK are said to reference or refer to the relation R2. iii) A value of FK in a tuple (record) t1 of the current state r(R1) either occurs as a value of PK for some tuple t2 in the current state r(R2) or is null. In the former case, we have t1[FK] = t2[PK], and we say that the tuple t1 references or refers to the tuple t2. FK Example: Employee(SSN, …, Dno) Dept(Dno, … )

  6. Relationships Window ConsultantID is primary key in Consultant table Relationship line ConsultantID is foreign key in Clients table

  7. Delete Record button Click + to display related records You cannot delete a Consultant without first deleting related Clients

  8. EMPLOYEE fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno DEPARTMENT Dname, dnumber, mgrssn, mgrstartdate Dnumber, dlocation PROJECT DEPT _LOCATIONS Pname, pnumber, plocation, dnum WORKS_ON Essn, pno, hours DEPENDENT Essn, dependentname, sex, bdate, relationship

  9. Updating and constraints delete • Delete the WORK_ON tuple with Essn = ‘999887777’ and pno = 10. • When deleting, the referential constraint will be checked. - The following deletion is not acceptable: Delete the EMPLOYEE tuple with ssn = ‘999887777’ - reject, cascade, modify

  10. ... ssn 123456789 ... delete delete Essn Pno 123456789 5 ... ... Cascade deletion – a strategy to enforce referential integrity Employee Works-on

  11. Employee delete delete delete ... ... ... ... ssn ssn supervisor supervisor 234589710 234589710 123456789 123456789 ... ... ... ... null null 234589710 234589710 cascade – a strategy to enforce referential integrity Employee not reasonable

  12. Modify (cascade updating) – a strategy to enforce referential integrity ... ssn Employee 123456789 ... delete Works-on Works-on Essn Pno Essn Pno 5 null 123456789 5 ... ... ... ... This violates the entity constraint.

  13. ... ssn 123456789 ... Department Department ... ... Dno chairman Dno chairman null 5 123456789 5 ... ... Modify (cascade updating) – a strategy to enforce referential integrity Employee delete This does not violate the entity constraint.

  14. Normalization We discuss four normal forms: first, second, third, and Boyce-Codd normal forms 1NF, 2NF, 3NF, and BCNF Normalization is a process that “improves” a database design by generating relations that are of higher normal forms. The objective of normalization: “to create relations where every dependency is on the key, the whole key, and nothing but the key”.

  15. Functional Dependencies We say an attribute, B, has a functional dependency on another attribute, A, if for any two records, which have the same value for A, then the values for B in these two records must be the same. We illustrate this as: A  B Example: Suppose we keep track of employee email addresses, and we only track one email address for each employee . Suppose each employee is identified by their unique employee number. We say there is a functional dependency of email address on employee number: employee number email address

  16. EmpNum EmpEmail EmpFname EmpLname 123 jdoe@abc.com John Doe 456 psmith@abc.com Peter Smith 555 alee1@abc.com Alan Lee 633 pdoe@abc.com Peter Doe 787 alee2@abc.com Alan Lee If EmpNum is the PK then the FDs: EmpNum EmpEmail EmpNum EmpFname EmpNum EmpLname must exist.

  17. Transitive dependency Consider attributes A, B, and C, and where A  B and B  C. Functional dependencies are transitive, which means that we also have the functional dependency A  C We say that C is transitively dependent on A through B.

  18. EmpNum  DeptNum EmpNum EmpEmail DeptNum DeptNname DeptNum  DeptName EmpNum EmpEmail DeptNum DeptNname DeptName is transitively dependent on EmpNum via DeptNum EmpNum  DeptName

  19. A partial dependency exists when an attribute B is functionally dependent on an attribute A, and A is a component of a multipart candidate key. InvNum LineNum Qty InvDate Candidate keys: {InvNum, LineNum} InvDate is partially dependent on {InvNum, LineNum} as InvNum is a determinant of InvDate and InvNum is part of a candidate key

  20. First Normal Form We say a relation is in 1NF if all values stored in the relation are single-valued and atomic. 1NF places restrictions on the structure of relations. Values must be simple.

  21. Boyce-Codd Normal Form BCNF is defined very simply: a relation is in BCNF if it is in 1NF and if every determinant is a candidate key. InvNum LineNum ProdNum Qty InvNum, LineNum ProdNum {InvNum, LineNum} and {InvNum, ProdNum} are the two candidate keys. Qty InvNum, ProdNum LineNum

  22. Second Normal Form A relation is in 2NF if it is in 1NF, and every non-key attribute is fully dependent on each candidate key. • 2NF (and 3NF) both involve the concepts of key and non-key attributes. • A key attribute is any attribute that is part of a key; any attribute that is not a key attribute, is a non-key attribute. • Relations that are not in BCNF have data redundancies • A relation in 2NF will not have any partial dependencies

  23. Consider this InvLine table (in 1NF): InvNum LineNum ProdNum Qty InvDate InvNum, LineNum ProdNum There are two candidate keys. Qty InvNum, ProdNum LineNum Qty is the only non-key attribute, and it is dependent on InvNum InvNum InvDate Since there is a determinant that is not a candidate key, InvLine is not BCNF InvLine is not 2NF since there is a partial dependency of InvDate on InvNum InvLine is only in 1NF

  24. EmployeeDept ename ssn bdate address dnumber dname inv_no line_no prod_no prod_desc qty InvNum LineNum ProdNum Qty InvNum InvDate

  25. Third Normal Form a relation is in 3NF if the relation is in 1NF and all determinants of non-key attributes are candidate keys That is, for any functional dependency: X  Y, where Y is a non-key attribute (or a set of non-key attributes), X is a candidate key. this definition of 3NF differs from BCNF only in the specification of non-key attributes - 3NF is weaker than BCNF. (BCNF requires all determinants to be candidate keys.) A relation in 3NF will not have any transitive dependencies

  26. EmpNum EmpName DeptNum DeptName We correct the situation by decomposing the original relation into two 3NF relations. Note the decomposition is lossless. DeptNum DeptName EmpNum EmpName DeptNum

  27. In 3NF, but not in BCNF: Instructor teaches one course only. student_no course_no instr_no Student takes a course and has one instructor. {student_no, course_no}  instr_no instr_no  course_no since we have instr_no  course-no, but instr_no is not a Candidate key.

  28. student_no course_no instr_no BCNF student_no instr_no course_no instr_no {student_no, instr_no}  student_no {student_no, instr_no}  instr_no instr_no  course_no

  29. Tables Forms Reports Practice Part Queries Macros not covered VBA modules

  30. Tables - table name - attribute name - attribute data type - attribute properties - Primary key - Foreign key

  31. Data Types of Fields • Attachment    Files, such as digital photos. Multiple files can be attached per record. This data type is not available in earlier versions of Access. • AutoNumber    Numbers that are automatically generated for each record. • Currency    Monetary values. • Date/Time    Dates and times. • Hyperlink    Hyperlinks, such as URL addresses. • Memo    Long blocks of text and text that use text formatting. A typical use of a Memo field would be a detailed product description. • Number    Numeric values, such as distances. Note that there is a separate data type for currency. • OLE Object    OLE objects (OLE object: An object supporting the OLE protocol for object linking and embedding. • Text    Short, alphanumeric values, such as a last name or a street address. • Yes/No    Boolean values.

  32. Properties • Field size- Adjusts the size of the text field • Format- changes the way field is displayed. Does not effect the value. • Input Mask- facilitates data entry • Caption- Label used for the field • Default Value- the automatically entered value • Validation Rule- Rejects records that do not conform to rules entered. • Validation Text- Error returned when validation rule is broken. • Required- Forces user to enter in value if selected. • Allow Zero Length- Allows text length of 0. • Indexed- increases efficiency of search on the field

  33. Examples for Format property Format property for Number data type: #,###.##;(#,###.##)[Red];0,000.00;“Undefined” format for null-value format for positive number format for 0 format for negative number 6,789.77

  34. Examples for Input Mask property Input mask for Text data type: !\(999") "000\-0000;0;_ e.g.(204) 888-1234 >!“FJ”-AA\-00000 e.g.FJ-EA-12048 Input mask for Time data type 99:00:00\ >LL;0;_ e.g.05:56:00 PM

  35. Forms different components: - bound controls - unbound controls - calculated controls - drop-down list box (combo box) - check box - option group - command buttons

  36. Subforms

  37. Subforms are generated using Wizard

  38. Subsubforms

  39. Subforms are generated using Subform/Subreport button

  40. Switchboard is a special form created using Switchboard manager (not covered)

  41. Reports seven sections: - report header - page header - group header - details - group footer - page footer - report footer

  42. Queries different kinds of queries: - select queries - action queries make-Table query, delete-table query append-Table query, update query parameter query, unmatched query, find-duplicates query - crosstab query - total queries group by aggregate functions: count, sum, maximum, minimum, Average

  43. Query design grid

  44. SQL statement Select FirstName, LastName From Employees Where Salary > 40000

More Related