Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 1 File Systems and Databases Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel l 工程資料庫專題 –NTUST/ME-2007Q4.

Similar presentations


Presentation on theme: "1 Chapter 1 File Systems and Databases Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel l 工程資料庫專題 –NTUST/ME-2007Q4."— Presentation transcript:

1 1 Chapter 1 File Systems and Databases Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel l 工程資料庫專題 –NTUST/ME-2007Q4

2 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 2 Database Management Database is shared, integrated computer structure housing: –End user data –Metadata Database Management System (DBMS) –Manages Database structure –Controls access to data –Contains query language

3 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 3 File Terminology Data –Raw Facts Field –Group of characters with specific meaning Record –Logically connected fields that describe a person, place, or thing File –Collection of related records

4 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 4 Simple File System Figure 1.5

5 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 5 File System Critique File System Data Management –Requires extensive programming in third- generation language (3GL) –Time consuming –Makes ad hoc queries impossible –Leads to islands of information

6 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 6 File System Critique (con’t.) Data Dependence –Change in file’s data characteristics requires modification of data access programs –Must tell program what to do and how –Makes file systems cumbersome from programming and data management views Structural Dependence –Change in file structure requires modification of related programs

7 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 7 Database Systems Database consists of logically related data stored in a single repository Provides advantages over file system management approach –Eliminates inconsistency, data anomalies, data dependency, and structural dependency problems –Stores data structures, relationships, and access paths

8 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 8 Database vs. File Systems Figure 1.6

9 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 9 Database System Environment Figure 1.7

10 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 10 DBMS Functions Data dictionary management Data storage management Data transformation and presentation Security management Multiuser access control Backup and recovery management Data integrity management Database language and application programming interfaces Database communication interfaces

11 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 11 Relational Database Model Perceived by user as a collection of tables for data storage Tables are a series of row/column intersections Tables related by sharing common entity characteristic(s)

12 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 12 Relational Database Model (con’t.) Figure 1.11

13 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 13 Relational Database Model Advantages –Structural independence –Improved conceptual simplicity –Easier database design, implementation, management, and use –Ad hoc query capability with SQL –Powerful database management system

14 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 14 Relational Database Model Disadvantages –Substantial hardware and system software overhead –Poor design and implementation is made easy –May promote “islands of information” problems

15 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 15 Entity Relationship Database Model Complements the relational data model concepts Represented in an entity relationship diagram (ERD) Based on entities, attributes, and relationships Figure 1.13

16 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 16 Entity Relationship Database Model Advantages –Exceptional conceptual simplicity –Visual representation –Effective communication tool –Integrated with the relational database model Disadvantages –Limited constraint representation –Limited relationship representation –No data manipulation language –Loss of information content

17 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 17 Object-Oriented Database Model Objects or abstractions of real-world entities are stored –Attributes describe properties –Collection of similar objects is a class Methods represent real world actions of classes Classes are organized in a class hierarchy – Inheritance is ability of object to inherit attributes and methods of classes above it

18 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 18 OO Data Model Advantages –Adds semantic content –Visual presentation includes semantic content –Database integrity –Both structural and data independence Disadvantages –Lack of OODM –Complex navigational data access –Steep learning curve –High system overhead slows transactions

19 1 Chapter 5 Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel

20 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 20 Introduction to SQL Ideal database language –Create database and table structures –Perform basic data management chores (add, delete, and modify) –Perform complex queries to transform data into useful information SQL is the ideal DB language –Data definition language –Data manipulation language

21 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 21 Good Reasons to Study SQL ANSI standardization effort led to de facto query standard for relational database Forms basis for present and future DBMS integration efforts Becomes catalyst in development of distributed databases and database client/server architecture

22 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 22 Data Definition Commands Create database structure –Holds all tables and is a collection of physical files stored on disk –DBMS automatically creates tables to store metadata –Database administrator creates structure or schema Logical group of tables or logical database Groups tables by owner Enforces security CREATE SCHEMA AUTHORIZATION Example: CREATE SCHEMA AUTHORIZATION JONES

23 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 23 Creating Table Structure Tables store end-user data May be based on data dictionary entries CREATE TABLE ( );

24 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 24 Data Manipulation Commands Common SQL Commands Table 5.3

25 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 25 Data Entry and Saving Enters data into a table Saves changes to disk INSERT INTO VALUES (attribute 1 value, attribute 2 value, … etc.); COMMIT ;

26 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 26 Listing Table Contents and Other Commands Allows table contents to be listed UPDATE command makes data entry corrections ROLLBACK command restores database back to previous condition if COMMIT hasn’t been used DELETE command removes table row SELECT FROM ;

27 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 27 Queries Creating partial listings of table contents SELECT FROM WHERE ; Table 5.4 Mathematical Operators

28 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 28 Examples Mathematical operators Mathematical operators on character attributes Mathematical operators on dates SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE FROM PRODUCT WHERE V_CODE <> 21344; SELECT P_CODE,P_DESCRIPT,P_ONHAND,P_MIN,P_PRICE FROM PRODUCT WHERE P_CODE < ‘1558-QWI’; SELECT P_DESCRIPT,P_ONHAND,P_MIN,P_PRICE,PINDATE FROM PRODUCT WHERE P_INDATE >= ‘01/20/2002’;

29 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 29 Computed Columns New columns can be created through valid computations or formulas –Formulas may contain mathematical operators –May contain attributes of any tables specified in FROM clause Alias is alternate name given to table or column in SQL statement SELECT P_DESCRIPT,P_ONHAND,P_PRICE,P_ONHAND*P_PRICE AS TOTVALUE FROM PRODUCT;

30 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 30 Operators Logical: AND, OR, NOT Rules of precedence –Conditions within parenthesis executed first –Boolean algebra Special –BETWEEN - defines limits –IS NULL - checks for nulls –LIKE - checks for similar string –IN - checks for value in a set –EXISTS - opposite of IS NULL SELECT * FROM PRODUCT WHERE V_CODE = 21344 OR V_CODE = 24288;

31 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 31 Advanced Data Management Commands ALTER - changes table structure ADD - adds column MODIFY - changes column characteristics Entering data into new column ALTER TABLE ADD ( ); ALTER TABLE MODIFY ( ); UPDATE PRODUCT SET P_SALECODE = ‘2’ WHERE P_CODE = ‘1546-QQ2’;

32 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 32 Advanced Data Management Commands (con’t.) Dropping a column Arithmetic operators and rules of precedence ALTER TABLE VENDOR DROP COLUMN V_ORDER; Table 5.5

33 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 33 Advanced Data Management Commands (con’t.) Copying parts of tables Deleting a table from database Primary and foreign key designation INSERT INTO SELECT FROM ; DROP TABLE PART; ALTER TABLE LINE ADD PRIMARY KEY (INV_NUMBER, LINE_NUMBER) ADD FOREIGN KEY (INV_NUMBER) REFERENCES INVOICE ADD FOREIGN KEY (PROD_CODE) REFERENCES PRODUCT;

34 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 34 Example Aggregate Function Operations COUNT MAX and MIN SELECT COUNT(DISTINCT V_CODE) FROM PRODUCT; SELECT COUNT(DISTINCT V_CODE) FROM PRODUCT WHERE P_PRICE <= 10.00; SELECT MIN(P_PRICE) FROM PRODUCT; SELECT P_CODE, P_DESCRIPT, P_PRICE FROM PRODUCT WHERE P_PRICE = MAX(P_PRICE);

35 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 35 Example Aggregate Function Operations (con’t.) SUM AVG SELECT SUM(P_ONHAND * P_PRICE) FROM PRODUCT; SELECT P_DESCRIPT, P_ONHAND, P_PRICE, V_CODE FROM PRODUCT WHERE P_PRICE > (SELECT AVG(P_PRICE) FROM PRODUCT) ORDER BY P_PRICE DESC;

36 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 36 More Complex Queries and SQL Functions Ordering a listing Results ascending by default –Descending order uses DESC Cascading order sequence ORDER BY ORDER BY DESC ORDER BY

37 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 37 Procedural SQL SQL shortcomings –Doesn’t support execution of stored procedures based on logical condition –Fails to support looping operations Solutions –Embedded SQL can be called from within procedural programming languages –Shared Code is isolated and used by all application programs. –Procedural SQL (PL/SQL) stored within the database, executed by DBMS, and invoked by the end user Triggers Stored procedures PL/SQL functions

38 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 38 Procedural SQL (con’t.) Procedural SQL allows the use of procedural code and SQL statements that are stored within the database. The procedural code is executed by the DBMS when it is invoked by the end user. End users can use procedural SQL (PL/SQL) to create: –Triggers –Stored procedures –PL/SQL functions

39 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 39 Stored Procedures Named collection of procedural and SQL statements stored in database Invoked by name Executed as unit Invoked with EXEC CREATE OR REPLACE PROCEDURE procedure_name (argument IN/OUT data-type, etc) IS/AS BEGIN DECLARE variable name and data type PL/SQL or SQL statements; END; EXEC store_procedure_name (parameter, parameter, …)

40 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 40 PL/SQL Stored Functions Named group of procedural and SQL statements that returns a value Invoked from within stored procedures or triggers Cannot be invoked from within SQL statements CREATE FUNCTION function_name (argument IN data-type, etc) RETURN data-type AS BEGIN PL/SQL statements; RETURN (value); …… END;

41 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 41 Artist Database ERD and Tables Figure 5.55

42 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 42 General Rules Governing Relationships Among Tables Figure 5.57: M:N, Both Sides Optional Figure 5.56: M:N, Both Sides Mandatory

43 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 43 General Rules Governing Relationships Among Tables (Con’t.) Figure 5.58: M:N, One Side Optional Figure 5.59: 1:M, Both Sides Mandatory

44 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 44 General Rules Governing Relationships Among Tables (Con’t.) Figure 5.60: 1:M, Both Sides Optional Figure 5.61: 1:M, Many Side Optional, One Side Mandatory

45 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 45 General Rules Governing Relationships Among Tables (Con’t.) Figure 5.62: 1:M, One Side Optional, One Side Mandatory Figure 5.63: 1:1, Both Sides Mandatory

46 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 46 General Rules Governing Relationships Among Tables (Con’t.) Figure 5.64: 1:1, Both Sides Optional Figure 5.65: 1:1, One Side Optional, One Side Mandatory

47 1 Database Systems: Design, Implementation, & Management, 5 th Edition, Rob & Coronel 47 General Rules Governing Relationships Among Tables (Con’t.) Figure 5.66: Weak Entity, Foreign Key Located in Weak Entity Figure 5.67: Multivalued Attributes (New Table in 1:M Relationship, Foreign Key CAR_VIN in the New Table


Download ppt "1 Chapter 1 File Systems and Databases Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel l 工程資料庫專題 –NTUST/ME-2007Q4."

Similar presentations


Ads by Google