CS (204)321 ระบบฐานข้อมูล 1 (Database System I) บทที่ 2 ระบบฐานข้อมูล อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
เนื้อหา 1) ลักษณะการประมวลผลของระบบฐานข้อมูล (Major characteristic of database approach) 2) สภาพแวดล้อมของระบบฐานข้อมูล (Database system environment) 3) ประเภทของการประยุกต์ฐานข้อมูล (The range of database application) 4) สถาปัตยกรรมแบบรับและให้บริการ (Client/Server Architecture) 5) ประโยชน์ของการใช้ระบบจัดการฐานข้อมูล 6) องค์ประกอบของระบบจัดการฐานข้อมูล 7) หน้าที่ของระบบจัดการฐานข้อมูล 8) หลักการของระบบฐานข้อมูลและสถาปัตยกรรม
Major Characteristics of Database Approach Self-describing nature of a database system A DBMS catalog stores the description of the database. The description is called meta-data. This allows the DBMS software to work with different databases A traditional file processing can work with only one specific database. The description of the database is declared by data definition in the application program. For example, C and C++ program have “struct” or “class” declaration. Insulation between program and data Allows changing data storage structures without having to change the DBMS access programs called program-data independence. Changing in the structure of data files, embedded in the access programs, requires to change all programs that access this file.
Major Characteristics of Database Approach Data abstractions A data model is used to hide storage details and present the user with a conceptual view of the database. (data model – logical concepts – objects, properties, relationships) In traditional file processing, the representation of the structure of data files is very complicated. Details that are not of interest cannot be hidden. Support of multiple views of data Each user may see a different view of the database, which describes only the data of interest to that user. A traditional file processing cannot provide a different view of the database.
Major Characteristics of Database Approach Sharing of data and multiuser transaction processing DBMS allows multiple users to access the database at the same time. DBMS controls concurrent transactions from multiple users to operate correctly without interference so that data are updated correctly. A traditional file processing limits data sharing.
Database System Environment Users/Programmers DATABASE SYSTEM Application Programs/Queries DBMS SOFTWARE Software to Process Queries/Programs Software to Access Stored Data Stored Database Definition (Meta-Data) Stored Database Source: Elmasri R. & Navathe S.B. (1994) Fundamentals of database systems
Examples of Database A UNIVERSITY database for maintaining information concerning students, courses, and grades in a university environment. To define this database, we must specify The structure of the records. For example, each STUDENT record includes data to represent the student’s Name, StudentNumber, Class (freshman or 1, sophomore or 2,…), and Major (MATH, computer science or COSC, …).
Examples of Database A data type for each data element within record. e.g. Name of STUDENT is a string of alphabetic characters, StudentNumber of STUDENT is an integer, Grade of GRADE_REPORT is a single character from the set {A,B,C,D,F,I}, Class of a STUDENT as 1 for freshman, 2 for sophomore, 3 for junior, 4 for senior, and 5 for graduate student.
Examples of Database To construct the UNIVERSITY database, we store data to represent each student, course, section, grade report, and prerequisite as a record in the appropriate file. Records in the various files may be related to one another. Database manipulation involves querying and updating. Example of query is “retrieve all courses and grades of Smith”.
Intro to Computer Science Examples of Database STUDENT Name StudentNumber Class Major Smith 17 1 COSC Brown 8 2 COURSE CourseName CourseNumber CreditHours Department Intro to Computer Science COSC1310 4 COSC Data Structures COSC3320 Discrete Mathematics MATH2410 3 MATH Database COSC3380 PREREQUISITE CourseNumber PrerequisiteNumber COSC3380 COSC3320 MATH2410 COSC1310 Source: Elmasri R. & Navathe S.B. (1994) Fundamentals of database systems
Examples of Database SECTION SectionIdentifier CourseNumber Semester Year Instructor 85 MATH2410 Fall 91 King 92 COSC1310 Anderson 102 COSC3320 Knuth 112 Chang 119 135 COSC3380 Stone GRADE_REPORT StudentNumber SectionIdentifier Grade 17 112 B 119 C 8 85 A 92 102 135 Source: Elmasri R. & Navathe S.B. (1994) Fundamentals of database systems
Database System Environment องค์ประกอบย่อย 5 ส่วน ส่วนอุปกรณ์ (Hardware) ได้แก่ Personal computer Mainframe Computer network Printer และอื่นๆ ส่วนชุดคำสั่ง (Software) ได้แก่ Operating system DBMS และ Application program ระเบียบวิธีปฏิบัติ (Procedure) คือคำสั่งหรือกฎเกณฑ์ที่ใช้ในการออกแบบและวิธีการใช้ระบบฐานข้อมูล ข้อมูล คือ ข้อเท็จจริงที่จะนำไปบันทึกในฐานข้อมูล อาจเป็นข้อมูลดิบที่จะถูกนำไปประมวลผลและสร้างเป็นสารสนเทศ บุคลากร (People) คือ บุคคลที่เกี่ยวข้องกับการทำงานระบบฐานข้อมูล
Different Types of Database Users Workers on the scene Persons whose job involves daily use of a large database. Database administrators (DBA) Responsible for managing the database system – authorizing, coordinating and monitoring. 2) Database designers Responsible for designing the database – identifying and choosing appropriate structures. 3) End users The persons that use the database for querying, updating, generating reports, etc.
Different Types of Database Users 3) End users The persons that use the database for querying, updating, generating reports, etc. There are several categories of end users. 3.1. Casual end users: They occasionally access the database. 3.2. Naïve or parametric end users: They perform canned transaction. e.g. bank teller or reservation clerk. 3.3. Sophisticated end users: They familiarize with DBMS and implement complex applications. 3.4. Stand-alone users: They maintain personal database by using ready-made program packages. 4) System analysts and application programmers They determine requirements, design, and implement canned transactions for parametric user.
Different Types of Database Users Workers behind the scene Persons whose job involves design, development, operation, and maintenance of the DBMS software and system environment. DBMS designers and implementers Design and implement the DBMS modules and interfaces as a software package. 2) Tool developers Design and implement tools that facilitate the use of DBMS software. Tools include design tools, performance tools, special interfaces, etc. 3) Operators and maintenance personnel They responsible for the actual running and maintenance of the hardware and software environment for the database system.
Database Architectures|Client/Server Architecture user user client Application Application client network network Application server Database system server Database system Two-tier architecture Three-tier architecture Source: Silberschatz A., Korth, H.F. & Sudarshan S. (2006) Database system concepts.
Database Architectures|Client/Server Architecture Two Tier Client-Server Architectures Application on client machine invokes database system functionality at the server machine through query language statements. Application program interface like ODBC (Open Database Connectivity) and JDBC (Java Database Connectivity) are used for interaction. Three Tier Client-Server Architectures Client machine communicates with application server only which means it does not contain any direct database calls. Application server communicates with a database system to access data. Appropriate for large applications, and web applications.
ประโยชน์ของการใช้ระบบจัดการฐานข้อมูล มีดังนี้ การควบคุมความซ้ำซ้อนของข้อมูล (Controlling data redundancy) การหลีกเลี่ยงความขัดแย้งของข้อมูล (Data inconsistency) การใช้ข้อมูลร่วมกัน (Sharing of data) การควบคุมมาตรฐาน (Enforcement of standard) การบังคับใช้กฎความคงสภาพ (Enforcement of integrity constraints) ความเป็นอิสระของข้อมูล (Program-data independence) ความง่ายในการพัฒนา (Reduced application development time) การสำรองข้อมูลและการฟื้นสภาพข้อมูล (Backup and recovery) การเข้าถึงและเรียกใช้ข้อมูลได้หลากหลายวิธี (Multiple user interface)
องค์ประกอบของระบบจัดการฐานข้อมูล Users/Programmers DATABASE SYSTEM Application Programs/Queries DBMS SOFTWARE Report writer/Report generator Queries processor Security system Database engine Stored Database Definition (Meta-Data) Stored Database
หน้าที่ของระบบจัดการฐานข้อมูล มีดังนี้ การจัดการพจนานุกรมข้อมูล (Data dictionary management) การจัดการหน่วยเก็บข้อมูล (Data storage management and transformation) การจัดการความปลอดภัย (Security management) การจัดการความคงสภาพของข้อมูล (Data integrity management) การควบคุมภาวะการทำงานพร้อมกัน (Multi-user access control) การสำรองข้อมูลและการฟื้นสภาพข้อมูล (Backup and recovery management) ภาษาสำหรับเข้าถึงฐานข้อมูล (Database access language) การติดต่อประสานกับฐานข้อมูล (Database communication interface)
หลักการของระบบฐานข้อมูลและสถาปัตยกรรม
Data Models Data model “A set of concepts that can be used to describe the structure of a database (data types and relationships) and certain constraints that the database should obey.” “Operations for specifying database retrievals and updates by referring to the concepts of the data model.” Operations on the data model may include basic operations and user-defined operations. (e.g. A user-defined operation is COMPUTE_GPA which can be applied to a STUDENT object.) Data model operations
Data Models Categories of data models 1) Conceptual (high-level, semantic) data models: Provide concepts that are close to the way many users perceive data. 2) Physical (low-level, internal) data models: Provide concepts that describe the details of how data is stored in the computer. 3) Implementation (representational) data models: Provide concepts that fall between above two, balancing user views with some computer storage details.
Schemas VS. Instances In any data model it is important to distinguish between the description of the database and the database itself. Database schema (or meta-data) “The description of database. It includes description of database structure and the constraints that should hold on the database.” The database schema is specified during database design and is not expected to change frequently. e.g. Name: string StudentNumber: string Class: integer Major: string
Schemas VS. Instances Schema diagram “A diagrammatic display of a database schema – structure of each record type (not the actual instances of a record).” STUDENT Name StudentNumber Class Major COURSE CourseName CourseNumber CreditHours Department PREREQUITSITE CourseNumber PrerequisiteNumber SECTION SectionIdentifier CourseNumber Semester Year Instructor GRADE_REPORT StudentNumber SectionIdentifier Grade
Schemas VS. Instances Schema construct “An object within the schema.” e.g. STUDENT, COURSE. Database instances “The actual data stored in a database at a particular moment in time. Also called database state or occurrence.” Many database instances can be constructed to correspond to a particular database schema.
DBMS ensures valid state Schemas VS. Instances Define a new DB initial state Data firstly loaded Database Update operation Database DBMS ensures valid state Specify DB schema DBMS catalog empty state Database
Schemas VS. Instances Distinction The database schema does not frequently change, but the database state changes every time the database is updated. Schema is also called intension, whereas state is called extension.
Three-Schema Architecture The three-schema architecture was proposed to support DBMS characteristics of : Program-data independence. Supporting multiple views of the data. The goal of the three-schema architecture is to separate the user applications and the physical database.
Three-Schema Architecture Schema can be defined at the following three level. 1) Internal schema at the internal level Describes physical storage structures and access paths. Typically uses a physical data model. 2) Conceptual schema at the conceptual level Describes the structure (such as entities, data type, relationship) and constraints for the whole database. Uses a conceptual or implementation data model. 3) External schemas at the external level Describes the various user views. Usually uses the same data model as the conceptual level.
Three-Schema Architecture END USERS EXTERNAL VIEW1 EXTERNAL VIEWn External level Conceptual level CONCEPTUAL SCHEMA Internal level INTERNAL SCHEMA STORED DATABASE Source: Elmasri R. & Navathe S.B. (1994) Fundamentals of database systems.
Three-Schema Architecture Mappings among schema levels are needed to transform requests and data. If the request is a database retrieval, the data extracted from the stored database must be reformatted to match the user’s external view. Programs refer to an external schema, and are mapped by the DBMS to the internal schema for execution. Notice that the three schemas are only descriptions of data; the only data that actually exists is at the physical level.
Data Independence Two types of data independence: 1) Logical data independence The capacity to change the conceptual schema without having to change the external schemas and their application programs. 2) Physical data independence The capacity to change the internal schema without having to change the conceptual (or external) schema.
Data Independence When a schema at a lower level is changed, only the mappings between this schema and higher-level schemas need to be changed in a DBMS that fully supports data independence. The higher-level schemas themselves are unchanged. Therefore, the application programs need not be changed since they refer to the external schemas.
Three-Schema Architecture END USERS EXTERNAL VIEW1 EXTERNAL VIEWn External level Logical data independence Conceptual level CONCEPTUAL SCHEMA Physical data independence Internal level INTERNAL SCHEMA STORED DATABASE Source: Elmasri R. & Navathe S.B. (1994) Fundamentals of database systems.
DBMS Language Once the design of a database is completed and a DBMS is chosen to implement the database: Data Definition Language (DDL) is used by the DBA and by database designers to define the conceptual schema for the database and any mapping between the two. Storage Definition Language (SDL) is used to specify the internal schema. View Definition Language (VDL) are used to specify external schema - user views and their mappings to the conceptual schema.
DBMS Language Once the database schemas are compiled and the database is populated with data: Data Manipulation Language (DML) are used to specify database retrievals and updates. DML commands (data sublanguage) can be embedded in a general-purpose programming language (host language), such as COBOL, C or an Assembly Language. In object-oriented systems, the host and data sublanguages typically form one integrated language such as C++. Alternatively, a high-level DML used in stand-alone interactive manner is called a query language.
DBMS Language Types of DML 1) Procedural DML (record-at-a-time or low-level DML) Must be embedded in a programming language. Typically retrieve individual records from the database, and use looping and other constructs of the host programming language to retrieve multiple records. Specify how to retrieve data. e.g. COBOL, C, etc.
DBMS Language 2) Declarative or Non-procedural DML (set-at-a-time or high-level DML) Use as a stand-alone query language or embedded in a programming language. Typically retrieves information from multiple related database records in a single command. Specify what data to retrieve than how to retrieve. Also called declarative languages. e.g. SQL