Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concepts of Database Management, 4th Edition, Pratt & Adamski

Similar presentations


Presentation on theme: "Concepts of Database Management, 4th Edition, Pratt & Adamski"— Presentation transcript:

1 Concepts of Database Management, 4th Edition, Pratt & Adamski
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management, 4th Edition, Pratt & Adamski

2 Concepts of Database Management, 4th Edition, Pratt & Adamski
Objectives Define, describe, and use views Use indexes to improve database performance Discuss entity, referential, and legal-values integrity Make changes to the structure of a relational database Define and use the system catalog Concepts of Database Management, 4th Edition, Pratt & Adamski

3 Concepts of Database Management, 4th Edition, Pratt & Adamski
Views Application program’s or individual user’s picture of the database Less involved than full database Offers simplification Provides measure of security Sensitive tables or columns omitted where not appropriate Concepts of Database Management, 4th Edition, Pratt & Adamski

4 SQL to Create View Figure 4.1
CREATE VIEW Housewares AS SELECT PartNum, Description, OnHand, Price FROM Part WHERE Class=‘HW’ ; Concepts of Database Management, 4th Edition, Pratt & Adamski

5 Housewares View of Database
Figure 4.2 Concepts of Database Management, 4th Edition, Pratt & Adamski

6 Concepts of Database Management, 4th Edition, Pratt & Adamski
Query on a View Selects data only from Tables created in the view Query is merged with query used to create view SELECT * FROM Housewares WHERE OnHand< 25 ; Actually executes as SELECT PartNum, Description, OnHand, Price FROM Part WHERE Class=‘HW’ AND OnHand< 25 ; Concepts of Database Management, 4th Edition, Pratt & Adamski

7 Access Query Design of View
Figures Concepts of Database Management, 4th Edition, Pratt & Adamski

8 Access Query Design of View with Changed Field Names
Figures Concepts of Database Management, 4th Edition, Pratt & Adamski

9 SalesCust View SQL Statement
CREATE VIEW SalesCust (Snum, SLast, SFirst, Cnum, CName) AS SELECT Rep.RepNum, LastName, FirstName, CustomerNum, CustomerName FROM Rep, Customer WHERE Rep.RepNum=Customer.RepNum ; Concepts of Database Management, 4th Edition, Pratt & Adamski

10 Concepts of Database Management, 4th Edition, Pratt & Adamski
SalesCust View Figure 4.7 Concepts of Database Management, 4th Edition, Pratt & Adamski

11 Concepts of Database Management, 4th Edition, Pratt & Adamski
Access Query Design of SalesCust View Figure 4.8 Concepts of Database Management, 4th Edition, Pratt & Adamski

12 of SalesCust View (con’t.)
Access Query Design of SalesCust View (con’t.) Figure 4.9 Concepts of Database Management, 4th Edition, Pratt & Adamski

13 Concepts of Database Management, 4th Edition, Pratt & Adamski
Advantages of Views Provides data independence Same data viewed by different users in different ways Contains only information required by a given user Concepts of Database Management, 4th Edition, Pratt & Adamski

14 Concepts of Database Management, 4th Edition, Pratt & Adamski
Indexes Conceptually similar to book index Increases data retrieval efficiency Automatically assigns record numbers Used by DBMS, not by users Fields on which index built called Index Key Concepts of Database Management, 4th Edition, Pratt & Adamski

15 Customer Table with Record Numbers
Figure 4.10 Concepts of Database Management, 4th Edition, Pratt & Adamski

16 Customer Table Index on CustomerNum
Figure 4.11 Concepts of Database Management, 4th Edition, Pratt & Adamski

17 Concepts of Database Management, 4th Edition, Pratt & Adamski
Table Indexes on CreditLimit, RepNum Figure 4.12 Concepts of Database Management, 4th Edition, Pratt & Adamski

18 Concepts of Database Management, 4th Edition, Pratt & Adamski
Pros/Cons of Indexes Can be added or dropped without loss of function Can make retrieval more efficient Occupies space that might be required for other functions DBMS must update index whenever corresponding data are updated Concepts of Database Management, 4th Edition, Pratt & Adamski

19 Concepts of Database Management, 4th Edition, Pratt & Adamski
SQL to Create Index CREATE INDEX CustomerName ON Customer (CustomerName) ; Concepts of Database Management, 4th Edition, Pratt & Adamski

20 Concepts of Database Management, 4th Edition, Pratt & Adamski
SQL to Delete Index DROP INDEX RepBal ; Concepts of Database Management, 4th Edition, Pratt & Adamski

21 Index on Single Field in Access
Figure 4.13 Concepts of Database Management, 4th Edition, Pratt & Adamski

22 Index on Multiple Fields in Access
Figure 4.14 Concepts of Database Management, 4th Edition, Pratt & Adamski

23 Concepts of Database Management, 4th Edition, Pratt & Adamski
Security Prevention of unauthorized access to database Two SQL security mechanisms GRANT provides privileges to users REVOKE removes privileges from users GRANT SELECT ON Customer TO JONES ; REVOKE SELECT ON Customer FROM JONES ; Concepts of Database Management, 4th Edition, Pratt & Adamski

24 Concepts of Database Management, 4th Edition, Pratt & Adamski
Integrity Rules Related to foreign keys and primary keys Defined by Dr. E.F. Codd Entity integrity No field that is part of the primary key may accept null values Referential integrity If Table A contains a foreign key matching the primary key of Table B, then values must match for some row in Table B or be null Concepts of Database Management, 4th Edition, Pratt & Adamski

25 Concepts of Database Management, 4th Edition, Pratt & Adamski
Primary Key in Access Figure 4.15 PRIMARY KEY (CustomerNum) Concepts of Database Management, 4th Edition, Pratt & Adamski

26 Multi-Field Primary Key in Access
Figure 4.16 PRIMARY KEY (OrderNum, PartNum) Concepts of Database Management, 4th Edition, Pratt & Adamski

27 Relationships Window to Relate Tables in Access
Figure 4.17 FOREIGN KEY (RepNum) REFERENCES Rep Concepts of Database Management, 4th Edition, Pratt & Adamski

28 Specifying Referential Integrity
Figure 4.18 Concepts of Database Management, 4th Edition, Pratt & Adamski

29 Violating Referential
Integrity on Adding Figure 4.19 Concepts of Database Management, 4th Edition, Pratt & Adamski

30 Violating Referential
Integrity on Deleting Figure 4.20 Concepts of Database Management, 4th Edition, Pratt & Adamski

31 Legal-Values Integrity
States no record can exist with field values other than legal ones Use SQL CHECK clause CHECK (CreditLimit IN (5000, 7500, 10000, 15000)) ; Concepts of Database Management, 4th Edition, Pratt & Adamski

32 Concepts of Database Management, 4th Edition, Pratt & Adamski
Other SQL Adding new field ALTER TABLE Customer ADD CustType CHAR(1) ; Changing field properties ALTER TABLE Customer CHANGE COLUMN CustomerName TO CHAR(50) ; Concepts of Database Management, 4th Edition, Pratt & Adamski

33 Concepts of Database Management, 4th Edition, Pratt & Adamski
Add Field in Access Figure 4.22 Concepts of Database Management, 4th Edition, Pratt & Adamski

34 Characteristic in Access
Change Field Characteristic in Access Figure 4.23 Concepts of Database Management, 4th Edition, Pratt & Adamski

35 Concepts of Database Management, 4th Edition, Pratt & Adamski
Other SQL Deleting field ALTER TABLE Part DELETE Warehouse ; Delete SQL Table DROP TABLE SmallCust ; Concepts of Database Management, 4th Edition, Pratt & Adamski

36 Concepts of Database Management, 4th Edition, Pratt & Adamski
Delete Field in Access Figure 4.24 Concepts of Database Management, 4th Edition, Pratt & Adamski

37 Concepts of Database Management, 4th Edition, Pratt & Adamski
Delete Table in Access Figure 4.25 Concepts of Database Management, 4th Edition, Pratt & Adamski

38 Concepts of Database Management, 4th Edition, Pratt & Adamski
System Catalog Information about database kept in system catalog Maintained by DBMS Example catalog has two tables Systables Syscolumns Concepts of Database Management, 4th Edition, Pratt & Adamski

39 Concepts of Database Management, 4th Edition, Pratt & Adamski
Systables Table Figure 4.26 Concepts of Database Management, 4th Edition, Pratt & Adamski

40 Partial Syscolumns Table
Figure 4.27 Concepts of Database Management, 4th Edition, Pratt & Adamski


Download ppt "Concepts of Database Management, 4th Edition, Pratt & Adamski"

Similar presentations


Ads by Google