Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sample Table Standard Notation Entity name in uppercase

Similar presentations


Presentation on theme: "Sample Table Standard Notation Entity name in uppercase"— Presentation transcript:

1 Sample Table Standard Notation Entity name in uppercase
Accession Number DeweyCode Title Author Date Published 88 121.9 Let’s Cook Chan, C 1992 123 Electricity Glendenning, V 1995 300 Riders Cooper, J 657 200.00 Greek in 3 weeks Stavros, G 1990 etc… Standard Notation BOOK(AccessionNo, DeweyCode, Title, Author,DatePublished) Entity name in uppercase Key field (unique identifier) is underlined All attributes are shown in brackets, separated by commas ANS ( Normaliziation)

2 Primary Keys This is a field that is used to uniquely define a particular record or line in a table. Since text fields e.g. surname can be repeated, primary keys are nearly always numeric fields. They can include: Membership number, product number, employee number, catalogue number, account number. SECONDARY KEY A secondary key is a field or attribute that is not necessarily unique but is used for example to sort or order the data. An example above might be the supplier name in the supplier table. ANS ( Normaliziation)

3 Foreign Keys Video Table Video Rentals Table
This is a field in one table which is also the primary key of another table. Foreign keys are used to establish a relationship between the main table and other subsidiary tables. Customer Table Customer ID First Name Surname Address Telephone number Age Gender Video Table Video ID Video title Rating Film Genre Date Released Length of film Rental price Video Rentals Table Video_Rental ID Customer ID Video ID Date Rented Date Returned ANS ( Normaliziation)

4 Relational database A RELATIONAL database. A relational database is one which allows more than one individual table (also called a relation) to be connected together. ANS ( Normaliziation)

5 Linking Database Tables
One-to-many Tables may be linked through the use of a common field. This field must be a key field of one of the tables and is known as foreign key in the second table. In a Library database two tables book and Borrower and makes a relationship Borrower Book borrows If there is another table of Loan which attributes as below LOAN( Association number, Borrower id, datedue Borrower Book has Loan consisting of ANS ( Normaliziation)

6 Linking Database ANS ( Normaliziation) Prepared by: Mazhar Javed Awan

7 Normalisation Normalisation is a process used to come up with the best possible design for a relational database. Tables should be organised in such a way that: No data is unnecessarily duplicated Data is consistent throughout the database Structure of each table is flexible enough to allow you to enter as many / few items as you want to The structure should enable a user to make all kinds of complex queries relating data from different tables ANS ( Normaliziation)

8 Sample data to be held in a database
Student number Student name Date of birth Sex Course number Course name Lecturer number Lecturer name 12345 Heathcote,R M EC6654,EC9011 EC4521 A Level Computing, Math A level, Physics T345267 T223459 T318743 Glover,T Todd,M Chapman 22433 Head,J F EC6654 AD6611 BM7634 A Level Computing Art French T886554 T165555 Lowry,B Burke,D 128867 Hargrave,R This data should be split into two tables, STUDENT and COURSE, in standard database notation: STUDENT(StudentNumber, StudentName, DateOfBirth,Sex) COURSE(CourseNumber,CourseName,LecturerNumber,LecturerName) Consider the problems of creating a relationship between these two tables. A link has to made between common fields ANS ( Normaliziation)

9 First normal form Definition: A table is in first normal form if it contains no repeating attributes or groups of attributes. Let’s look at a simple example of two entities STUDENT and COURSE. A student can take several courses, and each course has several students attending. The relationship can be represented by the entity-relationship diagram: STUDENT COURSE attends There is a many-to-many relationship between entities STUDENT and COURSE ANS ( Normaliziation)

10 Creating the relationship
We need a common field, but the problem is that because this is a many-to-many relationship, whichever table we put the link field into, there needs to be more than one field. e.g. STUDENT (student number, student name, date of birth, sex, course number) is no good because the student is doing several courses, so which one would be mentioned? Similarly, COURSE (course number, course name, lecturer number, lecturer name, student number) is no good either because each course has a number of students taking it. How about allowing space for 3 courses on each student record? STUDENT (student number, student name, date of birth, sex, course1, course2, course3) Why is this not a good idea? ANS ( Normaliziation)

11 Creating the relationship
What we have engineered is a repeating attribute – unacceptable in 1st normal form. In other words, the field course number is repeated 3 times The table is therefore NOT in first normal form. It would be represented in standard notation with a line over the repeating attribute: STUDENT (student number, student name, date of birth, sex, course number) To put the data into first normal form, the repeating attribute must be removed. ANS ( Normaliziation)

12 Creating the relationship
In its place, the field course number becomes part of the primary key in the student table. The tables are now as follows: STUDENT (student number, student name, date of birth, sex, course number) COURSE (course number, course name, lecturer number, lecturer name) Discussion: What is a primary key? Why does course number have to be part of the primary key? ANS ( Normaliziation)

13 The situation so far: STUDENT COURSE student no. student name D.O.B.
sex course no. 12345 Heathcote,R M EC6654 22433 Head,J F HM7756 AD1121 66688 Hargrave,R BM3390 STUDENT course no. course name Lecturer no. lecturer name EC6654 A-Level Computing T345267 Glover,T HM7756 A-Level Music T773351 Reader,B AD1121 Pottery T876541 BM3390 HNC Business T666758 Newman,P COURSE ANS ( Normaliziation)

14 Second Normal Form Only applicable if table has a compound key
A table is second normal form (2NF) if it is in first normal form and no column that is not part of the primary key is dependent on a portion of the primary key: This may be said as: A table in 2NF contains no partial dependencies The tables on the previous slide are not in 2NF because, for example, student name is dependent only on student number and not on course number To put the tables in 2NF we need to introduce a third table to link the two entities ANS ( Normaliziation)

15 The tables in 2nd Normal Form
STUDENT (student number, student name, date of birth, sex) STUDENT_TAKES (student number, course number) COURSE (course number, course name, lecturer number, lecturer name) What we had with the two entities was a many-to-many relationship This situation will always need a link table to create two one-to-many relationships ANS ( Normaliziation)

16 Third Normal Form A table in third normal form (3NF) contains no non-key dependencies The COURSES table contains an attribute for lecturer number and also one for lecturer name. Lecturer name is dependent on lecturer number (not on course number) Therefore a new table should be created for LECTURER ANS ( Normaliziation)

17 Normalised Files STUDENT (student number, student name, date of birth, sex) STUDENT_TAKES (student number, course number) COURSE (course number, course name, lecturer number) LECTURER (lecturer number, lecturer name) This is the optimum way of holding this data, with no duplication. The tables in Relational Databases should be in Third Normal Form ANS ( Normaliziation)

18 Comparing flat-files with RDB
A relational database is able to create links between tables representing different entities such as STUDENT and COURSE, through the use of foreign keys. A flat file system is not able to link tables It is only useful for very simple databases which contain information about just one entity. It is impossible to ‘normalise’ a database in a flat file system, since this involves correctly establishing links between tables Flat-file systems do not have any of the sophisticated features of a full DBMS such as the ability to set individual user-access rights, or allow several people to access the database at the same time ANS ( Normaliziation)


Download ppt "Sample Table Standard Notation Entity name in uppercase"

Similar presentations


Ads by Google