database concepts a database is an organized collection of logically related data. data are raw...

9
Database Concepts se is an organized collection of logically related data. Data •are raw facts.(not processed) •meaningless Information •processed data •meaningful 3A31 Kevin Cho i 37539322 15/08/19 92 3A30 Maria Leung 37545231 12/09/19 93 3A20 Billy Wong 37685454 16/08/19 94 Below are raw data ( 原原原原 ) StudI D StudName Phone DateBirt h 3A31 Kevin Cho i 3753932 2 15/08/19 92 3A30 Maria Leung 3754523 1 12/09/19 93 3A20 Billy Wong 3768545 4 16/08/19 94 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. Name Data structure Rules Description Data type Length Min Max Format StudID Number 4 Unique code that identifies the student StudName Text 30 Name of a student Phone Text 12 (852)- 98765432 Phone of a student DateBirt Date 8 Birthday of a student

Upload: rosamund-carson

Post on 18-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

Database ConceptsA database is an organized collection of logically related data.

Data•are raw facts.(not processed)•meaningless

Information•processed data•meaningful

3A31 Kevin Choi 37539322 15/08/19923A30 Maria Leung 37545231 12/09/19933A20 Billy Wong 37685454 16/08/1994

Below are raw data (原始數據 )

StudID StudName Phone DateBirth3A31 Kevin Choi 37539322 15/08/19923A30 Maria Leung 37545231 12/09/19933A20 Billy Wong 37685454 16/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.

Name Data structure Rules DescriptionData type Length Min Max Format

StudID Number 4 Unique code that identifies the studentStudName Text 30 Name of a studentPhone Text 12 (852)-98765432Phone of a studentDateBirth Date 8 Birthday of a student

Page 2: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

STRUCTURE OF DATA IN A DATABASEDatabaseA 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 numberEach 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

STUDENTStudID SubjectID Mark3A31 01 89

SUBJECT

Record number

3A30

.

0115/08/199237539322Kelvin Choi3A31

DateBirthPhoneStudNameStudID

Primary key

12/09/199337545231Maria Leung02

...

.

.

SUBJECTMARK

EnglishName

01

SubjectID

Page 3: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

DatabaseSCHOOL.mdb

STUDENT SUBJECTMARKStudID SubjectID mark3A313A313A303A30

01020102

56674578

SubjectID Name0102..

EnglishMath

.

.

SUBJECT

StudID

3A31

StudNameKelvin Choi

Phone37539322

DateBirth15/08/1992

.

...

Fields

characters

Records

Tables

databasetable

records

fieldscharacters

EXAMPLE OF DATABASE

Page 4: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

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.

Page 5: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

SCHOOL

Foreign keyis 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

STUDENT SUBJECTMARK

3A313A313A303A30

StudID56674578

01020102

marksSubjectID

EnglishMath

.

.

Name0102..

SubjectIDSUBJECT

15/08/199237539322Kelvin Choi3A31DateBirth

.

.

StudName

.

.

PhoneStudID

Primary key foreign key foreign key

Primary key

Page 6: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

A database consists of user data and Metadata, etc.

User DataTables

Meta Data (data dictionary)Contains structure of all tables and relationships among them.

Page 7: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

Characteristics of a relational database1. Data integrity(數據完整)

Integrity ConstraintsEnsure the accuracy and integrity of data.

1. Domain ConstraintsA 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 ConstraintsEvery table must have a primary key (must be unique and non-empty).

Must be unique

Must not be empty

Page 8: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

2. Referential Integrity ConstraintsRelationships between tables are established through foreign keys. Foreign key must be in the table on the many sidee.g. A student may study more than one subject.

Foreign keyPrimary key

Primary key

Addition of recordsA 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 recordsIf the studID of a student record changes, all corresponding records of the student changes as well in mark table.

Deletion of recordsIf 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 Primary key

Foreign key

Page 9: Database Concepts A database is an organized collection of logically related data. Data are raw facts.(not processed) meaningless Information processed

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 dataIntegration of the operated data may be possible to get additional information for the same data.Sharing of dataDatabase can be shared by all authorized (授權 ) users.Improved securityDatabase 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 maintenanceDatabase 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 scaleCost savings can be obtained by combining all organization's operational data into one database with applications to work on one source of data.