DBMS Lecture

download DBMS Lecture

of 30

Transcript of DBMS Lecture

  • 8/8/2019 DBMS Lecture

    1/30

    JkAs

    Computers In Management

  • 8/8/2019 DBMS Lecture

    2/30

    JkAs

    What is a Database ? A structuredcollection of Records and Data

    How is the structure achieved? Thestructure is achieved by organizing thedata according to a database model.

  • 8/8/2019 DBMS Lecture

    3/30

    JkAs

    What is a Database Model? A model that can be used to referto the graphical depiction of a database structure.

  • 8/8/2019 DBMS Lecture

    4/30

    JkAsDatabase Model

    A database model is a theory or specificationdescribing how a database is structured andused

    A data model is not just a way of structuringdata, it also defines a set of operations that can

    be performed on the data.Common models include:

    Flat Model Hierarchical model Network model Relational model

  • 8/8/2019 DBMS Lecture

    5/30

    JkAsF lat Model

    Also called Table Model

    Consists of a single, two-dimensional array of data elements, whereall members of a given column are assumed to be similar values,and all members of a row are assumed to be related to one another.

    S.NO Name Password

    1 ABC ****

    2 DEF ****

    3 GHI ****

    4 JKL ****

  • 8/8/2019 DBMS Lecture

    6/30

    JkAsHi erarch ical model

    Data is organized into a tree-like structure.

    It has a single upward link in each record to describe the nesting,and a sort field to keep the records in a particular order in eachsame-level list

  • 8/8/2019 DBMS Lecture

    7/30

    JkAs

    N etwork model

    It organizes data using two fundamental constructs, called recordsand sets.

    Records contain fields whereas sets define one-to-manyrelationships between records

  • 8/8/2019 DBMS Lecture

    8/30

    JkAs

    Hi erarch ical model Vs. N etwork model

    In the Network Modelbranches can be connected tomultiple nodes.

    Network model is able torepresent redundancy in datamore efficiently than in thehierarchical model.

  • 8/8/2019 DBMS Lecture

    9/30

    JkAs

    R elat ional Model

    A relational database is a single database spread across multiple table s.

    Three key terms are used extensively in relational database models:relat ions, attr ibutes, and doma ins . A relation is a table with columnsand rows. The named columns of the relation are called attributes, andthe domain is the set of values the attributes are allowed to take.

  • 8/8/2019 DBMS Lecture

    10/30

    JkAs

    R elat ional Model (Cont inued)All of the employee information is kept in the firstdrawer; all of the vendor information is kept in thesecond drawer; and all of the purchase orders arekept in the third drawer. To connect each of thesedrawers a set piece of data from one drawer has tobe present in one of the other drawers.

    A purchase order will have a vendor name, address,and phone number on it, along with the itemspurchased, purchase price, and any discounts.

    If the vendor name is the "set" piece of data, it isentered in the purchase order table, but theaddress & phone number are retrieved from thevendor table instead of having to re-type thatinformation each time it is needed in the purchaseorder table.

  • 8/8/2019 DBMS Lecture

    11/30

    JkAs

    R elat ional Database - N ormal iz at ion

    Normalization is a systematic way of

    ensuring that a database structure issuitable for general-purposequerying and free of certainundesirable characteristics.

    Insert ion Anomaly Update Anomaly Delet ion Anomal ies

    The anomalies could lead to a lossof data integrity.

  • 8/8/2019 DBMS Lecture

    12/30

    JkAs

    Insert ion Anomaly

    There are circumstances in which certain facts cannot be recorded at all.

    For example, each record in a "Faculty and Their Courses" table might containa Faculty ID, Faculty Name, Faculty Hire Date, and Course Code thus we canrecord the details of any faculty member who teaches at least one course, butwe cannot record the details of a newly-hired faculty member who has not yetbeen assigned to teach any courses.

  • 8/8/2019 DBMS Lecture

    13/30

    JkAs

    Update Anomaly

    The same information can be expressed on multiple rows; therefore upd ates

    to the table may result in logical inconsistencies.For example, each record in an "Employees' Skills" table might contain anEmployee ID, Employee Address, and Skill; thus a change of address for aparticular employee will potentially need to be applied to multiple records(one for each of his skills). If the update is not carried through successfully if,that is, the employee's address is updated on some records but not othersthen the table is left in an inconsistent state.

  • 8/8/2019 DBMS Lecture

    14/30

    JkAs

    Delet ion AnomalyThere are circumstances in which the deletion of data representing cert ainfacts necessitates the deletion of data representing completely different facts.

    The "Faculty and Their Courses" table described in the previous examplesuffers from this type of anomaly, for if a faculty member temporarily ceasesto be assigned to any courses, we must delete the last of the records on whichthat faculty member appears.

  • 8/8/2019 DBMS Lecture

    15/30

    JkAs

    Database Management System (DBMS)

    A database management system(DBMS) is computer software thatmanages databases. DBMSes may useany of a variety of database models,such as the network model orrelational model. In large systems, aDBMS allows users and other softwareto store and retrieve data in astructured way.

  • 8/8/2019 DBMS Lecture

    16/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    N ormal isat ion

    In the field of relational database design, normalization is a systematic wayof ensuring that a database structure is suitable for general-purposequerying and free of certain undesirable characteristicsinsertion, update,and deletion anomaliesthat could lead to a loss of data integrity.E.F. Codd, the inventor of the relational model, introduced the concept of

    normalization and what we now know as the first normal form in 1970.Codd went on to define the second and third normal fo rms in 1971 andCodd and Raymond F. Boyce defined the Boyce-Codd normal form in 1974.Informally, a relational database table is often described as "normalized" if it is in the third normal form (3NF). Most 3NF tables are free of insertion,update, and deletion anomalies.

  • 8/8/2019 DBMS Lecture

    17/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Fi rst N ormal Form

    A relation is in first normal form if all its attributes are simple. In other words, none of the attributes of the relation is a relation.Student-courses (Sid:pk, Sname, Phone, Courses-taken) Where attributeSid is the primary key, Sname is student name, Phone is student's phonenumber and Courses-taken is a table contains course-id, course-

    description, credit hours and grade for each course taken by the student.More precise definition of table Course-taken is :Course- taken (Course-id:pk, Course-description, Credit-hours, Grade)

  • 8/8/2019 DBMS Lecture

    18/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Student-courses

    Sid Sname Phone Courses-taken

    100 John 487 2454 St-100-courses-taken

    200 Smith 671 8120 St-200-courses-taken

    300 Russell 871 2356 St-300-courses-taken

    Course-id Course-description Credit-hours Grade

    IS380 Database Concepts 3 A

    IS416 Unix OperatingSystem

    3 B

    Course-id Course-description Credit-hours Grade

    IS380 Database Concepts 3 B

    IS416 Unix OperatingSystem

    3 B

    IS420 Data Net Work 3 C

    Course-id Course-description Credit-hours Grade

    IS417 System Analysis 3 A

    St-100-Course-taken

    St-200-Course-taken

    St-300-Course-taken

  • 8/8/2019 DBMS Lecture

    19/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Insertion anomaly means that that some data can not be inserted in thedatabase. For example we can not add a new course to the database of example-1,unless we insert a student who has taken that course.Update anomaly means we have data redundancy in the database and tomake any modification we have to change all copies of the redundant dataor else the database will contain incorrect data. For example in our database we have the Course description "Database Concepts" for IS380appears in both St-100-Course-taken and St-200-Course-taken tables. Tochange its description to "New Database Concepts" we have to change it

    in all places. Indeed one of the purposes of normalization is to eliminatedata redundancy in the database.Deletion anomaly means deleting some data cause other information to belost. For example if student Russell is deleted from St-100-Course-takentable we also lose the information that we had a course call IS417 withdescription System Analysis.

    Thus Student-courses table suffers from

    all the three anomalies.

  • 8/8/2019 DBMS Lecture

    20/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    To convert the above structure to first normal form relations, all non-simp leattributes must be removed or converted to simple attribute.

    To do that a new relation is created by combining each row of Student-courses with all rows of its corresponding course table that was taken bythat specific student.Student-courses ( Sid:pk1, Sname, Phone, Course-id:pk2, Course-description, Credit-hours, Grade)Notice that the primary key of this table is a composite key made up of twoparts; Sid and Course-id. Note that pk1 following an attribute indicates thatthe attribute is the first part of the primary key and pk2 indicates that theattribute is the second part of the primary key.

  • 8/8/2019 DBMS Lecture

    21/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Sid Sname Phone Course-id Course-description

    Credit-hour s

    Grade

    100 John 487 2454 IS380 Database Concepts 3 A

    100 John 487 2454 IS416 Unix Operating System 3 B

    200 Smith 671 8120 IS380 Database Concepts 3 B

    200 Smith 671 8120 IS416 Unix Operating System 3 B

    200 Smith 671 8120 IS420 Data Net Work 3 C

    300 Russell 871 2356 IS417 System Analysis 3 A

  • 8/8/2019 DBMS Lecture

    22/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Examination of the above Student-courses relation reveals that Sid doesnot uniquely identify a row (tuple) in the relation hence cannot be theprimary key. For the same reason Course-id cannot be the primary key.However the combination of Sid and Course-id uniquely identifies a row inStudent-courses, Therefore (Sid, Course-id) is the primary key of theabove relation.The primary key determines every attribute. For example if you know bothSid and Course-id for any student you will be able to retrieve Sname,Phone, Course-description, Credit-hours and Grade, because these

    attributes are dependent on the primary key.

  • 8/8/2019 DBMS Lecture

    23/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

  • 8/8/2019 DBMS Lecture

    24/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    W as the solution The Best

    Insertion anomaly: We cannot add a new course such as IS247 withcourse description programming techniques to the database unless weadd a student who to take the course.Update anomaly: If we change the course description for IS380 from

    Database Concepts to New_Database_Concepts we have to makechanges in more than one place or else the database will be inconsistent.In other words in some places the course description will beNew_Database_Concepts and in any place were we forgot to make thechanges the description still will be Database_Concepts.Deletion anomaly: If student Russell is deleted from the database we also

    loose information that we had on course IS417 with descriptionSystem_Analysis.

  • 8/8/2019 DBMS Lecture

    25/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Second Normal Form

    A first normal form relation is in second normal form if all its non-primaryattributes are fully functionally dependent on the primary key.To convert Student-courses to second normal relations we have to makeall non-primary attributes to be fully functionally dependent on the primarykey.To do that we need to project (that is we break it down to two or more

    relations) Student-courses table into two or more tables.To avoid such problems it is important to keep attributes, which aredependent on each other in the same table, when a relation is projected tosmaller relations.

  • 8/8/2019 DBMS Lecture

    26/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Sid Sname Phone100 John 487 2454

    200 Smith 671 8120

    300 Russell 871 2356

    Course-id Course-description

    Credit-hours

    IS380 Database Concepts 3

    IS416 Unix Operating System 3

    IS420 Data Net Work 3

    IS417 System Analysis 3

    Sid Course-id Grade100 IS380 A

    100 IS416 B

    200 IS380 B

    200 IS416 B

    200 IS420 C

    300 IS417 A

  • 8/8/2019 DBMS Lecture

    27/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    All these three relations are in second normal form. Examination of these relations shows that we have eliminated the redundancy in the database.Now relation Student contains information only related to the entitystudent, relation Courses contains information related to entity Coursesonly, and the relation Student-grade contains information related to therelationship between these two entity.Insertion anomaly: Now a new Course with course-id IS247 and Course-description can be inserted to the table Course. Equally we can add anynew students to the database by adding their id, name and phone to

    Student table. Therefore our database, which made up of these threetables does not suffer from insertion anomaly.U pdate anomaly: Since redundancy of the data was eliminated no updateanomaly can occur. To change the course-description for IS380 only onechange is needed in table Courses.D eletion anomaly: the deletion of student Russell from the database isachieved by deleting Russell's records from both Student and Student-grade relations and this does not have any side effect because the courseIS417 untouched in the table Courses.

  • 8/8/2019 DBMS Lecture

    28/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Tournament Year WinnerWinner Date of Birth

    Indiana Invitational 1998 Al Fredrickson 21 July 1975

    Cleveland Open 1999 Bob Albertson 28 September 1968

    Des MoinesMasters 1999 Al Fredrickson 21 July 1975Indiana Invitational 1999 Chip Masterson 14 March 1977

  • 8/8/2019 DBMS Lecture

    29/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Tournament Year Winner

    Indiana Invitational 1998 Al Fredrickson

    Cleveland Open 1999 Bob Albertson

    Des Moines Masters 1999 Al Fredrickson

    Indiana Invitational 1999 Chip Masterson

    Player Date of Birth

    Chip Masterson 14 March 1977

    Al Fredrickson 21 July 1975

    Bob Albertson 28 September 1968

  • 8/8/2019 DBMS Lecture

    30/30

    JkAs

    Copyright 2009 JkAs Management Consulting Group

    Third Normal Form

    A table whose non-primary key fields are dependent only on the primarykey and therefore have no dependence (relationship to) any other non-primary key field in the table is consider in third normal form (3NF). And,additionally the table must first be in 2nd normal form.