Slides Rdbms 1

77
Welcome to the course on Relational Database Management System.

Transcript of Slides Rdbms 1

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 1/76

Welcome to the course on Relational Database Management System.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 2/762

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 3/763

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 4/764

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 5/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 6/766

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 7/767

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 8/768

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 9/769

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 10/76

•In the traditional approach, information is stored in flat files which are maintained by the file

system of OS.

•Application programs go through the file system to access these flat files.

10

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 11/7611

Disadvantages of the traditional approach

Data Security: The data as maintained in the flat file(s) is easily accessible and therefore not secure.Example: Consider the Banking System. The Customer_Transaction file has details about the totalavailable balance of all customers. A Customer wants information about his account balance. In a filesystem it is difficult to give the Customer access to only his data. Thus enforcing securityconstraintsfor the entire file or for certain data items are difficult.

Data Redundancy: Often the same information is duplicated in two or more files.

The duplication of data also called redundancy leads to higher storage cost and access cost. It alsolead to data inconsistency

For Example, assume the same data is repeated in two or more files. If change is made to data in onefile, it is required that the change be made to the data in the other file as well. If this is not done, it willlead to error during access of the data.

Example: Assume Customer‟s details such as Cust_Last_Name, Cust_Mid_Name, Cust_First_Name,Cust_Email is stored both in the Customer_Details file and the Customer_Fixed_Deposit file. If theEmail ID of one Customer, for example, Langer S. Justin changes from [email protected] [email protected], the Cust_Email has to be updated in both the files; otherwise it willlead to inconsistent data.

However, one can design file systems with minimal redundancy. Data redundancy is sometimespreferred. Example: Assume the Customer‟s details such as Cust_Last_Name, Cust_Mid_Name,

Cust_First_Name and Cust_Email are not stored in the Customer_Fixed_Deposit file. If it is requiredto get this information about the customer along with his fixed deposit details, it would mean that thedetails be retrieved from two files. This would mean an increased overhead. It is thus preferred tostore the information in the Customer_Fixed Deposit file itself.

Data Isolation: Data Isolation means that all the related data is not available in one file. Generally, thedata is scattered in various files, and the files may be in different formats, therefore writing newapplication programs to retrieve the appropriate data is difficult.

Program/Data Dependence: Under the traditional file approach, application programs are dependenton the master and transaction file(s) and vice-versa. Changes in the physical format of the master file(s), such as addition of a data field requires that the change must be made in all the applicationprograms that access the master file. Consequently, for each of the application programs that aprogrammer writes or maintains, the programmer must be concerned with data management. There isno centralized[3] execution of the data management functions. Data management is scattered amongall the application programs.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 12/7612

Disadvantages of the traditional approach:

Example: Consider the banking system. A master file, Customer_Fixed_Deposit file exists which has details aboutthe customers fixed deposit accounts. A customer‟s fixed deposit record is described as follows:

Cust_ID

Cust_Last_Name

Cust_Mid_NameCust_First_Name

Cust_Email

Fixed_Deposit_No

Amount_in_Dollars

Rate_of_Interest_in_Percent

An application program is available to display all the details about the fixed deposit accounts of all the customers.Assume a new data field, the Fixed_Deposit_Maturity_Date is added to the master file. Because the applicationprogram depends on the master file, it also needs to be altered.

If the physical format of the master/transaction file for example the field delimiter, record delimiter, etc. arechanged, it necessitates that the application program which depends on it, also be altered.

Lack of Flexibility: The traditional systems are able to retrieve information for predetermined requests for data. If 

the management needs unanticipated data, the information can perhaps be provided if it is in the files of thesystem. Extensive programming is however required which may result in delay in making the information available.Thus by the time the information is made available, it may no longer be required or useful.

Example: Consider the banking system. An application program is available to generate a list of customer namesin a particular area of the city. The bank manager requires a list of customer names having an account balancegreater than $10,000.00 and residing in a particular area of the city. An application program for this purpose doesnot exist. The bank manager has two choices:

To print the list of customer names in a particular area of the city and then manually find out those with an accountbalance greater than $10,000.00

Hire an application programmer to write the application program for the same. Both the solutions arecumbersome.

Concurrent Access Anomalies: Many traditional systems allow multiple users to access and update the samepiece of data simultaneously. But the interaction of concurrent updates may result in inconsistent data.

Example: Consider the bank system. Assume the bank manager is analyzing all the transactions made by thecustomers. At the same time, a customer accesses his account to make a withdrawal. The account is both read bythe bank manager and updated by the customer at the same time. This is called concurrent access. Because thecustomer‟s account is being updated at the same time, there is a possibility of the bank manager reading an

incorrect balance.

These difficulties prompted the development of database systems.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 13/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 14/7614

• Now, the DBMS acts as a layer of abstraction on top of the File system.

• You might have observed that, for interacting with the file system, we were using high level languagefunctions for example, the „c‟ file handling functions. For interacting with the DBMS we would be using a

Query language called SQL.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 15/7615

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 16/7616

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 17/7617

In the above figure, the three level of DBMS architecture is depicted. The External view is

how the Customer, Jack views it.The Conceptual view is how the DBA views it.

The Internal view is how the data is actually stored.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 18/7618

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 19/7619

• DBA is a key person and takes care of most administrative tasks as mentioned in the slide.

• Database designers, design the database elements.

• Application programmers, make use of the various database elements and write programs to retrievedata from them.

• End users use the DBMS.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 20/7620

• Users and application programs need not know exactly where or how the data is stored in order toaccess it.

• 2. Proper database design can reduce or eliminate data redundancy and confusion.

• 3.Support for unforeseen (ad hoc) information requests are better supported - better flexibility.

• 4. Data can be more effectively shared between users and/or application programs.

• Data can be stored for long term analysis (data warehousing).

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 21/7621

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 22/7622

Commercial Packages

•Hierarchical Model –an example is IMS (Information Management System)

•Network Model – an example is IDMS (Integrated Data Management System)

•Relational Model – few examples are Oracle, DB2(DataBase 2)

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 23/7623

Record based data model – Hierarchical data model

Organizes the data in a Tree Structure

There is hierarchy of parents and child segments

Data is represented by a collection of records types

This restricts child segment having more than one parent

E.g.: Information Management System (IMS) from IBM

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 24/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 25/7625

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 26/7626

• Though logically data is viewed as existing in the form of two dimensional tables, actually, the data isstored under the file system only.

• The RDBMS provides an abstraction on top of the file system and gives an illusion that data resides inthe form of tables.

• Tuples in a relation are always unique,

• Example:

• If Student is a relation, each tuple of the relation will represent one student‟s information.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 27/76

Candidate Key

An attribute, or group of attributes, that is sufficient to distinguish every tuple in the relation from every other one.

 A candidate key is all those set of attributes which can uniquely identify a row. However, any subset of these set of attributes would not identify a row uniquely 

Primary key

The candidate key that is chosen to perform the identif ication task is called the primary key.

Every tuple must have, by definition, a unique value for its primary key. A primary keywhich is a combination of more than one attribute is called a composite primary key .

27

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 28/7628

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 29/7629

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 30/7630

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 31/7631

An attribute, or group of attributes, that is sufficient to distinguish every tuple in the relation from every other one.

 A candidate key is all those set of attributes which can uniquely identify a row. However, any subset of these set of attributes 

would not identify a row uniquely 

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 32/7632

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 33/7633

Overlapping candidate keys: Two candidate keys overlap if they involve any attribute in common. For e.g, in the above Customer 

table, Cust_Id, Account_No and Emailid, Account_No are two overlapping candidate keys. (they have Account_no in common)

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 34/7634

Primary key

The candidate key that is chosen to perform the identification task is called the   primary key.

Every tuple must have, by definition, a unique value for its primary key. A primary key which is a combination of more than one attribute is called a composite primary key  .

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 35/7635

Foreign key

•Usually a foreign key is a “copy” of a primary key that has been exported from one relation into another to

represent the existence of a relationship between them.

•Foreign key values do not (usually) have to be unique.

•Foreign keys can also be null  .

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 36/7636

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 37/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 38/7638

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 39/7639

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 40/7640

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 41/7641

• The spouse data is identified with the help of the employee id to which it is related

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 42/7642

Key attribute mentioned in the slide should not be miss understood with key attribute

discussion of relational model. The key attribute discussion here is only in the context of ERDiagram.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 43/7643

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 44/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 45/7645

• The minimum and maximum values of this connectivity is called the cardinality of the relationship

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 46/7646

• All employees will not be head-of some department. So only few instances of employee entityparticipate in the above relationship. But each department will be headed by some employee.

• So department entity‟s participation is total and employee entity‟s participation is partial in the above

relationship.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 47/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 48/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 49/7649

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 50/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 51/7651

Represented by an ellipse from which other ellipses emanate and represent the componentattributes. E.g Address

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 52/7652

• A unary relationship is represented as a diamond which connects one entity to itself as a loop.

• The relationship above means, some instances of employee manage other instances of Employee.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 53/7653

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 54/7654

A relationship between two entity types

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 55/7655

A relationship connecting three entity types.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 56/7656

•All instances of the entity type Employee don‟t participate in the relationship, Head-of.

•Every employee doesn‟t head a department. So, employee entity type is said to partiallyparticipate in the relationship.

•But, every department would be headed by some employee.

•So, all instances of the entity type Department participate in this relationship. So, we saythat it is total participation from the department side.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 57/7657

These attributes best describe the relationship prescription rather than any individual entity

Doctor, Patient or Medicine.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 58/7658

The identifying relationship is the one which relates the weak entity (dependant) with the

strong entity (Employee) on which it depends.Id is underlined with a dotted line because it is used to form composite key of dependententity along with E#.

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 59/7659

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 60/7660

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 61/7661

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 62/7662

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 63/7663

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 64/7664

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 65/7665

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 66/7666

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 67/7667

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 68/7668

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 69/7669

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 70/7670

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 71/7671

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 72/7672

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 73/76

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 74/7674

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 75/7675

8/6/2019 Slides Rdbms 1

http://slidepdf.com/reader/full/slides-rdbms-1 76/76