งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

Chapter 2 Relational Database

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "Chapter 2 Relational Database"— ใบสำเนางานนำเสนอ:

1 954245 Chapter 2 Relational Database
Modern Management and Information Technology Collage of Arts, Media and Technology Chiang Mai University

2 Outline The range of database applications
Relational database (definition and characteristic) Key Data Integrity Rules Relationship

3 What can databases help us do?

4 Database System Concept

5 1. The Range of Database Applications
It is important to understand that the applications and the database do not need to reside on the same computer. We divide the range of database applications into three categories based on the location of the client (application) and the database software itself Personal Two-tier Multitier databases

6 Personal Database Are designed to support one user and have long resided on PCs, laptops, smart phones and PDAs. Widely used because they improve personal productivity The data cannot easily be shared with other users and has other limitations

7 Personal Database Purpose
To provide the user with the ability to manage (store, update, delete, and retrieve) small amounts of data in and efficient manner. For example store customer information and the details of contacts consider a company that has a number of salespersons who call on actual or prospective customers A database of customers and pricing application can enable the salesperson to determine the best combination of quantity and type of items for the customer to order.

8 Two-tier Database with LAN
Characteristics of two- tier databases Workgroup Linked by network Sharing data Different user views (Authentication)

9 Two-tier Client/Server Database
The most common method of sharing data for user by creating a two-tier client/server application Each member of the workgroup has computer and linked by network (LAN) Database and database management system are stored on a central device called the database server (connected to network) Each member of workgroup has access to the shared data Different group members may have different user views of the shared database

10 Multitier Client/Server Database (n-tier)
The most significant implication for database development form the use of multitier client/server architectures is the ease of separating the development of the database and the modules that maintain the data from the information system modules that focus on business logic and / or presentation logic This architecture allows to improve performance and maintain ability of the application and database

11 Three-tier Architectures
Popular choice for internet application Includes another server layer in addition to the client and database server layers Increase scalability, flexibility, performance, and reusability

12 Three-tier Architectures

13 Three-tier Architecture
Workgroup has several multitier applications (between 25 and 100 persons) User interface is accessible on the individual user’s computers User interface: web browser based (written by Visual Basic.NET, Visual C#, or Java Application layer: contains the business logic required to accomplish the business transactions requested by users

14 n-tier Client Server Application servers Database servers
Management server

15 Summary of Database Applications
Type of Database/Application Typical Number of Users Typical Size of Database Personal 1 Megabytes Two-tier 5-100 Megabytes-gigabytes Three-tier 100-1,000 Gigabytes Enterprise resource planning (ERP) >100 Gigabytes-terabytes Data warehousing Terabytes-petabytes

16 Technical term technical term word Relation Table Tuple Row , Record
Attribute Column, Field Cardinality Number of Rows Primary Key Unique Identifier

17 2. Relational Database The notion "relational" is motivated by the mathematical concept of a relation. Relations in mathematics are sets of tuples. Relational databases are collections of one or more relations. In practice, relations can be visualized as tables, the rows of which are individual records of data with the same (homogeneous) field structure. The idea to organize data in tables is quite old and pretty obvious. The idea to investigate this representation of data by means of the theory of relations is due to one man, who proposed this view at the end of the 1960s: by Edgar F. Codd

18 Relational Database (RDB)
A relational database (RDB) is a collective set of multiple data sets organized by tables, records and columns. RDBs establish a well-defined relationship between database tables. Tables communicate and share information, which facilitates data searchability, organization and reporting. RDBs use Structured Query Language (SQL), which is a standard user application that provides an easy programming interface for database interaction.

19 Relational Database

20 Definition There are a set of tables.
The name of table is the name of relation. The columns in relation are called attributes. Domain is defined to data in the attribute that has same data type. The rows are called tuples.

21 Relational Database Attributes Degree = Cardinality = 3 4
Degree is the number of attributes. Cardinality is the number of rows. EmployeeNumber FirstName LastName 100 Mary Abermany 700 Jerry Caldera 300 Alea Copley 40 Murugan Jacksoni Degree = Cardinality = 3 4

22 Characteristic of data record in relation
1. No repeating data in each row

23 Characteristic of data record in relation
2. The order of data in each row is insignificant.

24 Characteristic of data record in relation
3. The order of data in each attribute is meaningless.

25 Characteristic of data record in relation
4. For each attributes, it can record only 1 value.

26 Characteristic of data record in relation
5. The value in each attribute record data in the same domain.

27 RDBs have many other advantages
Easy extendibility, as new data may be added without modifying existing records. This is also known as scalability. New technology performance, power and flexibility with multiple data requirement capabilities. Data security, which is critical when data sharing is based on privacy. For example, management may share certain data privileges and access and block employees from other data, such as confidential salary or benefit information.

28 3. Key Primary Key (PK) Foreign Key (FK) Candidate Key Composite Key

29 Primary Key (PK) An attribute or a combination of attributes that uniquely identifies each row in a relation Primary key is a unique identifier for a relation. There could be several candidate keys, as long as the they satisfy two properties: 1. uniqueness 2. minimality From the set of candidate keys, one is chosen to be the primary key. The others become alternate keys. EXAMPLE: The relation R has several candidate keys. ID SSN License_Number NAME If we select ID to be the primary key, then the other candidate keys become alternate keys. Uniqueness and minimal

30 Foreign keys provide the "links" between two relations.
Foreign key (FK) An attribute in a relation that serves as the primary key of another relation in the same database Foreign keys provide the "links" between two relations. database must not contain any unmatched foreign key values.

31 Candidate key (CK) An attribute, or combination of attributes, that uniquely identifies a row in a relation candidate key

32 Composite key A primary key that consists of more than one attribute
More than one attribute is needed to make the entity unique

33 Registration database
Please list all of PK, FK, CK? Student_id Course_id term Academic_year section grade Lecturer_id Student_id name surname address Telephone_no Course_id Course_name Description Unit Type Lecture_id LName LSurname Telephone Major_id Major_id Major_name

34 Null Values NULL is not the number zero.
NULL is not the empty string value. NULL is the value used to represent an unknown piece of data. Comparisons between two null values, or between a NULL and any other value, return unknown because the value of each NULL is unknown. Null ไม่ใช่ค่าที่เป็น 0 (กรณีเป็นตัวเลข) และไม่ใช่ space (ในกรณีเป็นข้อความ) Null หมายถึงไม่ทราบค่าหรือไม่รู้ค่าแน่ชัด Null เป็นศัพท์เฉพาะใน Relational Database หมายถึง ไม่ทราบค่าข้อมูลที่รู้แน่ชัด เราสามารถกำหนดให้ค่าของคอลัมน์ใดๆ เป็น Null ได้ (ถ้าเป็นไปได้ควรใส่ให้ครบจะดีที่สุด ) ยกเว้นคอลัมน์ที่เป็น Primary Key เพราะจะไม่สามารถนำ Primary Key มาใช้เข้าถึงข้อมูลในแต่ละแถวได้

35 4. Data Integrity Rules/Integrity Constraints
The relational data model includes several types of constraints, or rules limiting accept- able values and actions, whose purpose is to facilitate maintaining the accuracy and integrity of data in the database. The major types of integrity constraints are domain constraints, entity integrity, and referential integrity

36 4. Data Integrity Rules Data integrity rule is a procedure to control the accuracy and consistency of data stored in a database. There are 3 rules: Entity Integrity Domain Integrity Referential Integrity กฎควบคุมการคงสภาพของข้อมูล (Integrity Constraint) กฎการคงสภาพของข้อมูล หมายถึง กระบวนการที่ใช้สำหรับควบคุมความถูกต้องคล้องจองหรือมีความสมเหตุสมผลกันของข้อมูลใน database โดยการควบคุมการคงสภาพนั้น จะใช้คีย์หลัก (Primary key) และคีย์นอก (Foreign Key) เป็นเครื่องมือสำคัญ มีด้วยกัน 3 กฎ คือ กฎความคงสภาพของ Entity (Entity Integrity Rule) กฎความคงสภาพของ Domain (Domain Integrity Rule) กฎความคงสภาพของการอ้างอิง (Referential Integrity Rule)

37 Entity Integrity Every table must have a primary key and that the column or columns chosen to be the primary key should be unique and not null. Code Name แก้ว ใจเพชร มานี ใจใส่ มานะ ใจดี ปิติ ใจซื่อ กฎความคงสภาพของเอนติตี้ (Entity Integrity Rule) จะต้องไม่มี attribute ใดที่ประกอบขึ้นเป็นคีย์หลักของ relation มีข้อมูลที่เป็นค่าว่าง หรือ ค่าข้อมูลของคีย์หลัก (Primary key) จะต้องไม่เป็นค่าว่าง (Null Value)

38 Entity Integrity Entity integrity rule
Is designed to ensure that every relation has a primary key and that the data values for that primary key are all valid Guarantees that every primary key attribute is non-null Entity integrity rule No primary key attribute (or component of a primary key attribute) may be null

39 Domain Integrity Domain integrity means the definition of a valid set of values for an attribute. You define  - data type,  - length or size - is null value allowed - is the value unique or not for an attribute. Pcode Pname Ptype QTY Price 001 ปากกา 01 10 5 002 ดินสอ 20 2 003 โต๊ะ 03 5.5 1,600 004 โคมไฟ 02 4 500 2. กฎความคงสภาพของ Domain (Domain Integrity Rule) นิยามของขอบเขตของค่าที่เป็นไปได้ของ attribute หนึ่งๆ ที่ถูกกำหนดขึ้น เช่น เราต้องกำหนดคุณลักษณะต่างๆ ของข้อมูล ประเภทของข้อมูล ขนาด ยอมรับค่า null หรือไม่ สำหรับ attribute หนึ่ง ต้องเป็นค่าไม่ซ้ำกันหรือไม่ เป็นต้น

40 Domain Integrity All of the values that appear in a column of a relation must be from the same domain Domain is the set of values that may be assigned to an attribute Domain definition usually consists of the following components: domain name, meaning, data type, size (or length), and allowable values or allowable range (if applicable)

41 Domain Definitions for INVOICE Attributes
Domain Name Description Domain Cust_ID Customer ID Set of all possible customer ID Character: size 5 Cust_Name Customer Names Set of all possible customer names Character: size 25 Order_ID Order ID Set of all possible order ID OrderDate Order Dates Set of all possible order dates Date: format mm/dd/yy Product_ID Product ID Set of all possible product ID StandardPrice Unit Prices Set of all possible unit prices Double OrderQuantity Quantities Set of all possible orders quantities Integer: 3 digits

42 Referential Integrity
Product Any value of foreign key in the relation must be refer to the primary key value in another relation. Otherwise it must be null. Pcode Pname Ptype QTY Price 001 ปากกา 01 10 5 002 ดินสอ 20 2 003 โต๊ะคอมฯ 03 1,600 004 โคมไฟ 02 4 500 3. กฎความคงสภาพของการอ้างอิง (Referential Integrity Rule) ถ้า relation ใดมี attribute ที่เป็นคีย์นอก (Foreign Key) อยู่ ข้อมูลที่เป็นคีย์นอกนั้นจะต้องเป็นข้อมูลที่มีอยู่ใน Primary Key ของอีก relation หรือ ถ้าไม่แล้วข้อมูลที่เป็น foreign key จะต้องเป็นค่าว่าง Product Type Ptype Pname Location 01 เครื่องเขียน A2 02 ไฟฟ้า A5

43 Referential Integrity
Is a rule that maintains consistency among the rows of two relations If there is a foreign key in one relation, either each foreign key value must match a primary key value in another relation or the foreign key value must be null Referential integrity constraint A rule that states that either each foreign key value must match a primary key value in another relation or the foreign key value must be null

44 Modification affect to Referential Integrity
Delete the rows in the relation that their primary key are the foreign key in another relation. Modify the primary key value in the relation that refer to foreign key in another relation. การเปลี่ยนแปลงที่มีผลกระทบต่อกฎการคงสภาพของการอ้างอิง - การลบแถวหนึ่งๆ ในตารางที่มีคีย์หลักซึ่งเป็นคีย์นอกของอีกตารางหนึ่ง - การแก้ไขเปลี่ยนแปลงข้อมูลคีย์หลักซึ่งเป็นคีย์นอกของอีกตารางหนึ่ง

45 Modification affect to Referential Integrity
Pcode Pname Ptype QTY Price 001 ปากกา 01 10 5 002 ดินสอ 20 2 003 โต๊ะคอมฯ 02 1,600 004 โคมไฟ 4 500 Product Break the rule Product Type Ptype Pname Location 01 เครื่องเขียน A2 02 ไฟฟ้า A5 Change 02 to 04

46 3 cases to keep Referential Integrity
Cascade changing the primary key of a row in the primary table, the foreign key values are updated in the matching rows in the related table. Restricted changing the primary key of a row in the primary table can be done when there not refer to another relation as foreign key. Otherwise, modification can not be done. Nullifies changing the primary key of a row in the primary table, the foreign key values are set to null. DBMS มีวิธีการจัดการข้อมูลเพื่อให้เป็นไปตามกฎการคงสภาพที่นิยมอยู่ 3 วิธี กระทำแบบต่อเนื่อง (Cascade) คือ ถ้ามีการลบ หรือ เปลี่ยนแปลงข้อมูลที่เป็น primary key ที่มีการอ้างถึงแล้วจะต้องมีการลบหรือเปลี่ยนแปลงข้อมูลใน relation ที่มีการอ้างถึงนั้นด้วย กระทำแบบมีข้อจำกัด (Restricted) คือ DBMS จะอนุญาตให้ลบหรือเปลี่ยนแปลงข้อมูลที่เป็น Primary key ก็ต่อเมื่อ primary key นั้น ไม่ถูกอ้างอิงใน relation อื่นใด มิฉะนั้นจะปฏิเสธการลบหรือเปลี่ยนแปลง กระทำโดยการใส่ค่าว่าง (Nullifies) คือ DBMS จะยอมให้มีการลบหรือเปลี่ยนแปลงข้อมูลที่เป็น primary key ได้ แต่ต้องมีการใส่ค่าว่าง (Null Value) ลงไปยังข้อมูลของ attribute ที่เป็น foreign key ที่มีการอ้างอิงถึงข้อมูลที่ถูกลบหรือเปลี่ยนแปลง

47 Classification of relation
1. Base Relation Base Relation is a storage relation 2. View Relation that are authorized some views to each user Database ประกอบด้วยตารางหลายประเภท Base Relation เป็น relation ที่ถูกกำหนดขึ้นเพื่อเก็บข้อมูลเพื่อนำไปใช้ โดย Base Relation จะเป็น relation ที่เก็บข้อมูลอยู่จริง 2. วิว (View) เป็น relation ที่ถูกสร้างขึ้นตามความต้องการของผู้ใช้งานแต่ล่ะคน โดยจะกำหนด view ของตนขึ้นมาจาก base relation

48 5. Relationship Each table is known as a relation, which contains one or more data category columns. Each table record (or row) contains a unique data instance defined for a corresponding column category. One or more data or record characteristics relate to one or many records to form functional dependencies. Relationship (ความสัมพันธ์) แบ่งออกเป็น 3 ประเภท คือ One to One Relationship (1 – 1) One to Many Relationship (1 – M) Many to Many Relationship (M – N) ความสัมพันธ์แบบหนึ่งต่อหนึ่ง (One to One Relationship) เป็นความสัมพันธ์ที่เข้าใจง่ายที่สุด เป็นความสัมพันธ์ของข้อมูลใน 1 เรคอร์ดในตารางหนึ่งมีความสัมพันธ์กับข้อมูลอย่างมากหนึ่งข้อมูลกับอีกเรคอร์ดในอีกตารางหนึ่งเท่านั้นในลักษณะที่เป็นหนึ่งต่อหนึ่งนักศึกษา 1 คนเท่านั้นที่จะเป็นนายกองค์การนักศึกษา ความสัมพันธ์แบบหนึ่งต่อกลุ่ม (One to Many Relationship) เป็นความสัมพันธ์ที่พบบ่อยที่สุดในฐานข้อมูล เป็นความสัมพันธ์ของข้อมูลใน 1 เรคอร์ดในตารางหนึ่งมีความสัมพันธ์กับข้อมูลมากกว่าหนึ่งข้อมูลกับอีกเรคอร์ดในอีกตารางหนึ่งเท่านั้นในลักษณะที่เป็นหนึ่งต่อหนึ่งนักศึกษาแต่ละคนสามารถลงทะเบียนเรียนได้มากกว่า 1 วิชา ความสัมพันธ์แบบกลุ่มต่อกลุ่ม (Many to Many Relationship) เป็นความสัมพันธ์ของข้อมูลในเรคอร์ดใดๆ ของตารางหนึ่งมีค่าตรงกับข้อมูลของหลายๆ เรคอร์ดในตารางอื่นๆ รายวิชา 1 รายวิชามีอาจารย์สอนได้มากกว่า 1 คน การสั่งซื้อสินค้าในแต่ละครั้งสามารถสั่งซื้อสินค้าได้มากกว่า 1 ชนิด

49 Types of relationships in database
There are four relationships in database One to One (1-1): One table record relates to another record in another table One entity is associated with another entity. For Ex: Each employee is associated with one department One to Many (1-M): One table record relates to many records in another table One entity is associated with many other entities. For Ex: A company is associated with all working employees in one branch/office/country

50 Types of relationships in database
Many to One (M-1) Many entities are associated with only one entity. For Ex: Many employees are associated with one project. Many to Many (M-N) More than one table record relates to more than one record in another table Many entities are associated with many other entities. For Ex: In a company many employees are associated with multiple projects(completed/existing), and at the same time, projects are associated with multiple employees.

51 Question 1-1 1-M M-N

52 Question 1-1 1-M M-N

53 Question 1-1 1-M M-N

54 Glossary of Terms Schema
A structure that contains descriptions of objects created by a user, such as base tables, views, and constraints, as part of a database Base table A table in the relational data model containing the inserted raw data. Base tables correspond to the relations that are identified in the database’s conceptual schema Constraint A rule that cannot be violated by database users

55 Questions

56 References Hoffer, J.A., Ramesh, v., and Topi, H. (2013). Modern Database Management. 11th ed. ISBN Kroenke, D. M. (2006). Database Processing: Fundamentals, design, and implementation. Pearson Prentice Hall. New Jersey.

57 Web overview.html thi-2-rucak-kab-mysql-cluster to-create-a-multi-node-mysql-cluster-on-ubuntu-16-04 database-relationships


ดาวน์โหลด ppt Chapter 2 Relational Database

งานนำเสนอที่คล้ายกัน


Ads by Google