Download presentation
Presentation is loading. Please wait.
Published byRosamund Carson Modified over 9 years ago
1
Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed data meaningful 3A31Kevin Choi3753932215/08/1992 3A30Maria Leung3754523112/09/1993 3A20Billy Wong3768545416/08/1994 Below are raw data ( 原始數據 ) StudIDStudNamePhoneDateBirth 3A31Kevin Choi3753932215/08/1992 3A30Maria Leung3754523112/09/1993 3A20Billy Wong3768545416/08/1994 The data become meaningful information when a structure is provided. Metadata (which means “data about the data”) are the data that describe data structure, data definitions, rules and descriptions. It describes the properties of data but does NOT include the raw data. NameData structureRulesDescription Data typeLengthMinMaxFormat StudIDNumber4Unique code that identifies the student StudNameText30Name of a student PhoneText12(852)-98765432Phone of a student DateBirthDate8Birthday of a student
2
STRUCTURE OF DATA IN A DATABASE Database A database contains logically related tables. Tables ( 表格 ) A table is a group of related records. A table is identified by a table name. e.g. STUDENT, SUBJECT, SUBJECTMARK Records ( 記錄 ) A record is a set of related fields. Each record has an unique record number Each record is identified by a primary key, not by record number. e.g. StudID is primary key (uniquely identify a record) Two students could not have the same StudID. Fields ( 欄位 ) A field is a property of a certain object or event. e.g. ClassNo,StudName,Phone,DateBirth Characters -Represent field values of all data types. 15/08/199237539322Kelvin Choi3A31 DateBirthPhoneStudNameStudID 3A31 15/08/199237539322Kelvin Choi DateBirthPhoneStudNameStudID STUDENT StudIDSubjectIDMark 3A310189 SUBJECT Record number 3A30. 01 15/08/199237539322 Kelvin Choi3A31 DateBirthPhoneStudNameStudID Primary key 12/09/199337545231 Maria Leung 02......... SUBJECTMARK English Name 01 SubjectID
3
Database SCHOOL.mdb STUDENT SUBJECTMARK StudIDSubjectIDmark 3A31 3A30 01 02 01 02 56 67 45 78 SubjectIDName 01 02. English Math. SUBJECT StudID 3A31 StudName Kelvin Choi Phone 37539322 DateBirth 15/08/1992.. Fields characters Records Tables database table records fields characters EXAMPLE OF DATABASE
4
A database also contains relationships among tables. Tables are linked by relationships (with foreign keys and primary keys) Keys are used to organize, access, link tables and maintain database. Primary key is a field or combination of fields that uniquely identify a particular record in a table. Each table has one and only one primary key. unique (identify a particular record) and non-empty. e.g. STUDENT (StudID, StudName, Phone, DateBirth) StudID is a unique primary key to identify a particular student. Two students cannot have the same StudID. e.g. SUBJECT (SubjectID, Name) SubjectID is a unique primary key to identify a particular subject. Two subjects cannot have the same SubjectID. e.g. SUBJECTMARK (StudID, SubjectID, mark) StudID and SubjectID in SUBJECTMARK table together form a primary key to identify mark of a subject obtained by a student. Neither StudID nor SubjectID alone is unique. There could not be two marks for a subject taken by a student.
5
SCHOOL Foreign key is a field in one table that points to the primary key of another table for linking. e.g. StudID in SUBJECTMARK table alone is a foreign key that points to the primary key StudID in STUDENT table. SubjectID in SUBJECTMARK table alone is a foreign key that points to the primary key SubjectID in SUBJECT table. The foreign key StudID and SubjectID are underscored with a solid line since they are part of the primary key. e.g. There are many students in a school. But one student only belongs to one school. Add a foreign key SCHOOLID in STUDENT table (many side) and underscore it with a dotted line (since it is not part of primary key of STUDENT) to link to the primary key SCHOOLID of of the SCHOOL table (one side). STUDENT (StudID, StudName, Phone, DateBirth, SCHOOLID) SCHOOL(SCHOOLID, schoolname) foreign key Primary key STUDENTSUBJECTMARK 3A31 3A30 StudID 56 67 45 78 01 02 01 02 marksSubjectID English Math. Name 01 02. SubjectID SUBJECT 15/08/199237539322Kelvin Choi3A31 DateBirth. StudName. PhoneStudID Primary key foreign key Primary key
6
A database consists of user data and Metadata, etc. User Data Tables Meta Data (data dictionary) Contains structure of all tables and relationships among them.
7
Characteristics of a relational database 1. Data integrity( 數據完整) Integrity Constraints Ensure the accuracy and integrity of data. 1. Domain Constraints A domain is a set of values that may be assigned to an attribute. e.g. exam marks ranges from 0 to 100. A domain constraint defines data type, data size and allowable range. 2. Entity Integrity Constraints Every table must have a primary key (must be unique and non-empty). Must be unique Must not be empty
8
2. Referential Integrity Constraints Relationships between tables are established through foreign keys. Foreign key must be in the table on the many side e.g. A student may study more than one subject. Foreign keyPrimary key Addition of records A subject mark record for a student should not be entered in Mark table if there is no such student record in student table. Update of records If the studID of a student record changes, all corresponding records of the student changes as well in mark table. Deletion of records If a student record is deleted in student table, all corresponding records of the student will be deleted as well in mark table. e.g. A employee belongs to only one department. Primary key Foreign key
9
Advantages of DATABASE Reduced data redundancy( 減少重覆數據 ) eliminate the redundancy by integrating the files with foreign keys. Data are now stored only once. Whenever these data are needed, they are retrieved from another table based on foreign key. More information from the same amount of data Integration of the operated data may be possible to get additional information for the same data. Sharing of data Database can be shared by all authorized ( 授權 ) users. Improved security Database requires user names and passwords from users to access its data and grants different access rights to different users to retrieve, insert, update or delete data. Enforcement of standards ( 強制標準 ) Necessary standards including data formats, naming conventions, documentation standards, update procedures and access rules are enforced. Improved maintenance Database approach provides a data independence. As a change of data structure in the database will be affect the application program, it simplifies database application maintenance. Increased concurrency ( 同時性 ) Database can manage concurrent data access effectively. It ensures no interference between users that would not result any loss of information nor loss of integrity. Economy of scale Cost savings can be obtained by combining all organization's operational data into one database with applications to work on one source of data.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.