You are on page 1of 68
Introduction (May-2005, Mec-2008, 2 Maries] 1 Introduction to DBMS 2002, 2008, zans, 20051 Pétbue is 2 collection” of data. Ht contains’ information about one particular A database management sysier (OBMS) consists of a collection of interrelated and’ Sef of programs to access that data, DBMS is a set of Prewritten programs Faken (Oe: MPdate and retrieve a database, A DEMS comee the zation, Of database, The primary goal of th convenient and efficient to use in consistency, ‘The DBMS accepts requests for data from the application program and instructs Se operating system to transfer the appropriate date, When © DBMS is used. formation “systems can be changed much moxe casily as the organization’s Station requirements change. New categories of data can ie added to the Btsbise without disruption to the existing system. 41.2 Application Areas of DBMS Typical application areas of DBMS are Banking and financial services Culture and scientific information ‘Transport Tourism Database Management Systems: Telemedicine Natural resources management Production engineering Computerized Library systems ‘Automated teller machines Computerized parts inventory systems 1.4.3 Importance of DBMS Business fn much of world depends on database technology. The importance of DBMS in different sectors is given below Finance : JF database systems ane remaved it would take long EPS 12 process ai the nancial trancactions manually. The stock exchange also relies on omputer systems for recording buying and sling of stock which happens wery quickly and in large quantities, The amount of money involved in these transactions fs enormous. “pranspivt 's The silinas ail use. online seat sovecration 3737" and have systema for scheduling aircraft, for building ond mainis 0G timetables, for Trandling the in-flight catering and for mechanical serene of the planes. Similar qystens exist for Advantages : © I8is easy to develop relational model using ER model ‘+ E-R model specifies mapping eardinalities, + Ie specifies keys like primary key. * We can specify generalization and specialization using F-R diagram. > Disadvantage : () > * is Just used for database design nat for implementation. oy tse Relational Model nships among data by a collection of each of which has a number of columns with unique names Following Fig. 1.4 shows a sample relational database showing customers and accounts they have. For example, the customer Smith lives on Sidehill in Brooklyn, and has two accounts 101 and 245, numbered with 249 has balance Table name ; Customer Fig. 4.4 A sample relational database > Advantages : ‘The major advantages of the relational model are © Stinctural independance : When it is possible to make change to the database structure without affecting the DBMS's capability to access data, we can say that structural independence have been achieved. #¢ Management Systems 1-13 Introduction In relational database, changes in the database structure do not affect the data access. So relational database has structiral independence. * Conceptual simplicity : ‘The relational database model is simpler at the chrriual level. Since the relational date modiel fives the designer from the Physical data storage details, the designers can concentrate on the logical view of the database Design, implementation, maintenance and usage ease ; The relational database model achieves both dats independence and structural independence making the database design, Jnaintenance, administration and “sige much easier than the other madiele Good for ad hoc requests Ieis simpler to navigate Greater flexibility. > Disadvantages ; * Significant hardware and software overheads * Not as good for transaction. process modeling as hierarchieal and network + May have slower processing tines than hierarchical and network models, 15.3 Hierarchical Model A Nezarchical database is a Kind of database management system that links cea legether in a tree data structure such that each record type has only one ‘ver, ©, an order is owned by only one customer, Hierarchical structures wore widely’ used in the first main frame database management systems, Following Fig. 15 shows a sample hierarchical database model. Fig. 1.5 A sample hierarchical database Database Management Systems Management Sys * Advantages Be 16 shows a sampl High apeed of access to large datasets ieee Ease of updates. aie © Siipliity: The design of a hierarchical database is simple. © Data security = Hierarchical model was the first database model that off ome the data security that is provided and enforced by the DBMS * BMiciency : The hierarchical database model és a very efficient ene When database contains a large mumber of 1 : n relationships and when the u ‘ fg. MET Mumber of tansactions, using data who relatneen 25 a piventages fixed. = Conceptual simp! > Disadvantages is alse conceptual = Capability to ha handle the oneto = Data independes changes to the ap Disadvantages. = Detailed structur @ Lack of structural Tack of structural independence : Hierarch storage paths to nevigate to the different data segments. So if the physical structure is changed the applications will also have to be modified. Thus, ig # Hierarchical databese the benefils of data indepe structural dependence. Object-Orientec The object-oriented 5 stored in instanc that operate on the idence is limited by 1.5.4 Network Model [May-05,1 Marks] » advantages The network model is based on directed graph theory. The network model replaces the hierarchical tree w among the nodes. The main model is its ability to handle allows a record to have more two departments, + Applications req from the hierarchicalgy * Applications ms ips oF in other words, it an employee working for many-to-many (11: 1) relations! © Code is easier than one parent. Example is, + it provide B interrelationshig + Objectoriented Data access is € Database Management Systoms 1215 Hig. 16 shows a sample network model ere [tore [sere] ———f 00 eran | Sidanin | Brmon ‘Sidehil im ae 101 Kin | Lakeview [Penicce| 29 303, ‘00 Fig. 1.6 A sample notwork database > Advantages = Conceptual simplicity : Just like the hierarchical model, the network model is also conceptually simple and easy to design. Capability to handle more relationship types : The network model can handle the one-to-many (1: n) and many-to-many (a ; n) relationships. Data independence : The changes in data characteristics do nol require changes to the application programs. > Disadvantages © Detailed structural knowledge is required. ‘© Lack of structural independence. 455 Object-Oriented Model ‘The object-oriented model is based on a collectian of objects. Am object contains ‘eaiues stored in instance variables within the object. An object also contains bodies of seeds that operate on the object. These bodies of cade are called methods. Objects that ‘Ssikin the same types of values and the same methods are grouped together into —— > Advantages Applications require less code. Applications use more natural data model Code is easier to maintain It provides higher performance management of objects and complex interrelationships between objects. Object-oriented features improve productivity Data accuse is easy. Database Management Systems 4.5.6 Object Relational Model ‘A system thal includes both object infrastructure and a set of relational extend 4s called an object relational model. Object-relational systems combine the advanta ‘of modern objectoriented programming languages with relational database feat such as multiple views of data and a high-level, nonprocedural query language. of the object-telational systems available in the market are IDM's 82 unifargal se oracle corporations oracle 8, Microsoft Corporations SOL server 7 and so on. 1.5.7 Comparision between the Various Database Models. Ma ods | Data clement | Relationship Taentity | Aaseee tang frgantztion | representation Hierarchical Files, records Tee Record besed| Fracedural work Files, secords Graph Record based Relational Tables | Foreign key concopt| Value based (Objactorentes Objerss | Logical cartainwart | Resord based Procedural Gpeetraissonal Obiecs | Relstonal exenders| Value based | Nowgracedural Tabie 1.2 Various database modals 4.6 Database Languages A database system provides a data definition language to specify the datab schema and 2 data manipulation lasguage to express database queries and updat 4.6.1, Data Definition Language We specify a database schema by a set of definitions expressed by a spe Tanguage, called a Data Definition Language (DDL. DDL i 2 set of SOL commands used to create, modify and delete dati structures but not data. These commands are not noznally used by a general who should be accessing the database via an application. They are normally used the DBA toa limited extent, a database designer, or application developer. > Examples of DDL commands are © Create : To create objects in the database Example ‘create table accaunt (acoount_ro char10), palance integer); «| Alter: Alicr the structure of the database. © Drop : Deletes objects from the database. Truncate : Removes all records from 2 table, including all spaces allocated for the records are removed. ‘Comment : Add comments to the data dicklonary. Data Manipulation Language caipulation is= ‘= The retrieval of information stored in the database, “+ The insertion of new information into the database “= ‘The deletion of information from the database “The modification of information stored in the database. Data Manipulation Language (DML) is a language that enables users to access ate data as organized by the appropriate dala mods of Data Manipulation Languages are hwo types of DMLs @ Procedural DMIs : Require a user to specify what data are needed and how to ot those data. “G) Declarative DMIs (Nonpracedural DMLs) : Require 2 user to specify wint data arc needed without specifying how to get those data. sive DMLs are easier to lear and use than procedural DML, The DMI ef the SQL language is nonprocedural of DML commands are Insert : Insert data into a table. For exampl ingertinte account values eator’i090); Abave SQL DML statement inserls # record with values account_no = “A101 and balance = 1000 into account table. Update : Updates existing data within a table. Delete : Deletes all records from # table Query: A query is @ statement requesting, the retrieval of information. The portion of » DML that involves information retrieval is called a query language. Following query in the SOL language displays scrount information of account no = "ALON. select account no, balance from account ‘where account no = "AIOTS Database Management Systems 1-18 1 fi 1.7 Database System Architecture Ae [Dee-04, may-05, 07, 8 Marks; Dec-06, 12 Marks; Dec-07, 18 Marks} A database system is partitioned into modules that deal with each of the responsibilities of the averall sysiem. The fimetional components of « database systern can be broadly divided into the storage manager and the query processor components. Fig. 17 shows the overall system structure. Septintcaies & (oral See > a [ete ba. queries \ Database Management Systems: 1.7.1. Storage Manager |A. storage manager is a program module that provides the interface between the low level data stored in the database and the application programs and queries submitted to the system. The storage manager is responsible for the interaction with the file manager. The storage manager translates the various DML statements into low-level file system commands. Thus, the storage manager is responsible for storing, retrieving, and updating data in the database. ‘The various components of the storage manager are : + Authorization and integrity manager : It tezts for satisfaction of various integrity constraints and checks the authority of users accessing the data. ‘Transaction manager : It ensures that the database remains in a consistent state despite system failures, and concurrent executions proceed without conflicting File manager : It manages the allocation of space on disk storage and the data structures used to represent information stored on disk. Buffer manager : it is responsible for fetching datz from disk storage into main memory and deciding what data to cache in main memory. Storage manager = It implements several data structures as part of physical system implementation. Data files, which store the database itself Data dictionary : It contains metadata that is data about data. The schema of a table ic an example of metadata. A database system consults the data dictionary before reading and modifying actual data. Indices, which provide fast access to data ftems that hold particular values. 4 4.7.2 Query Processor aa The query processor is an important part of the database system. it helps the database system to simplify and facilitate access to data, ‘The query processor components include = DDL interpreter, which interprets DDI. statements and records the definitions in the data dictionary. DML compiler, which translates DML statements in a query language into an evaluation plan consisting of low-level instructions that the query evaluation engine understands. A query can be translated into any number af evaluation plans that all give the same result. The DML compiler also perfomn qiiery optimization, that is, it picks up the lowest cost evaluation plan from among the alternatives. Database Management Systems 1-29 Introduction * Query evaluation engine! which executes low-level instructions generated by the DML compiler. 1.8 Database Users and Administrator People who work with a database ean be calegorized a5 - © Database users + Database administrators 1.8.1 Database Users There are four different types of database system secs, differentiated by the wa they interact with the system : 2) Naive users: They ‘are unsophisticated users who interact with the system by invoking one g the application programs that have been wiitien previously. For example, a bank tell who needs to transfer $ 50 from account A to account B, invokes © Program called Einsier kis program asks the tele for the amount of money io be transferred, acount fom which the money is to be transferred, and the sccnnt to which th money is to be transferred, ‘The typical user interface for naive users is a forms interface, Where the user Ail in appropriate fields of the form. Naive users may also simply read report generated from the database, 8) Application programmers here are computer professionals who write application programs. Applicat Tene oer Gn eistee from ary tb io devel user “ere Rap Application Development (RAD) tools are tools that enable an application program: t© construct forms and reporis without w: also uses fourth generation Ianguages to ‘display of data on the screon. ©) Sophisticated users into instructions that sorage Manager understands. Analysts who submit queries to explose data in the database fall in this category. Online analytical processing (OLAF) tools simplify analysts tasks by lelting them Serr Shemini 0 Ania aciffecarl gwayes: Poe antaonces amalbct can eed Got} Database Menagoment Systems, 1521 Introduction by region (or exemple, North, South, Hast and West),.or by product, oF By cambination of region and product (that i, total sales of each product in each region). “Another class of tools for analyst is data mining tools, which help them to find certain Kinds of pattems in data 4) Specialized users ‘These ave sophisted users who write specialized database applications that do nat fit into the traditional data processing frame work Among these applications are computer sided design systems. knowledge base and. expert systems, systems that store data vith complex data types (for example, graphics data and audio-data) and environmient modelling systems. + 1.8.2 Database Administrator (Mmay-05, 07, Des-05, 2 Merks, Dec-06, 4 Marks, May-08, 6 Marks] ‘A person who has central control over the systems is called a database administrator (DBA). ‘The fianctions of a DBA include = = Schema definition : The DBA creates the original database schema by executing a set of data definition statements in the DDL. Schema and physical organization modification : The DBA. carries out changes to the schema and physical organization to reflect the changing needs of the organization, or to alter the phystcal organization te improve performance. Granting of authorization for data access : By granting diiferent types of authorization, the DBA can regulate different users accessing different parts ‘of database. Routine maintenance : Examples of database administrator's routine maintenance activities are = = Periodic backup, either onto tapes ar enfo remote servers, to prevent loss of data in case of disasters such as flooding. + Ensuring that enough free disk space is available for nocmal operations and ‘upgrading disk space as required. + Monitoring jobs rufning on the database and ensuring that performance is not degraded by very expensive tasks submitted by some users. Database Management Systems 4.9. Data Independence [Bec 03, May.08, 2 The ability to. modify a scheme definition in one level without affecting a sches definition in the next higher level is called data independdenace, There are two levels of data independence = D Physical data independence is the ability to modify the physical schem sthout causing application programs to be rewritten. Modifications at i Physical level are occasionally necessary in order to improve performance. 1) Togical data independence is the ability to modify the conceptual (log: Scheme without causing application programs to be rewritten, Modificetas the soneeptual level sre necessary whenever the logical structure ct a database %s altered (for example, the adition of money market accowne ie banking system). Logical data independence is more difficult to achieve than physical dai Independence since application programs are heavily dependent on the logics structure of the data they access. 1.40 Instances and Schemas Btay-04, Dec-05, 2 Marks: Dec-05, 4 Marke} Databases change over times as information is inserted and deleted. ‘The collection, formation stored in the database at a particular mament is called an instanes cr database, ‘The overall design of the database is called the database schema A database schema corresponds to the variable declarations im a program. Each Warlable has @ particular value at a given instant. The values of the vaeables arn Program at a point in time corresponds to an instance of » database schema, >» Types of database schemas 2D Physical schema : It describes the database design at the physical level 8) Wagical schema : It describes the database design at the logical love ND Subschema : A database muy also have several sabschemas at the view level, called as subschemas, that desctibe different views of the database 1.11 Entity Relationship Model (E-R Model) Database Management Systems 4.41.1 Basie Concepts ‘The F-R data model employs three basic notions : entity sets, relationship sets and attributes. 4) Entities and Entity Sets © An entity ic ‘thing’ or ‘object’ in the real world that is distinguishable from all other objects. For example, each person in an enterprise is an entity. An entity has a set of properties, and the values for some set of properties may uniquely identify an entity. For instsnce, a Customer with Customer id property with value C101 uniquely identifies that person. An entity may be concrete, such as person or a book. or it may be abstract, such as a loan or a holiday. ‘An entity set is a set of entities of the same type that share the same properties, or attributes. The set of all customers at a given bank can be defined as the entity sct Customer. Following Fig. 8 shows two entity sets : 4) Customer, with properties Customer_id, Customer_name, City. ii) Account with properties Account_no and Balance, ‘Customer id | Customernams | City coi Hen Senbey eta Ren Pune cto Jen Nashit 68 sin Salapur Gustomer Balance 3900 ‘A305 ‘2000 BAT 500 Fig. 1.8 Entity sets Customer and Account Ax enfity is represented by a sct of attibutes, Attributes are descriptive ruperties possessed by each member of an entity set. Database Management Systoms 128) + The attributes of Cusiomer entity set are Customer §d, Custoiner name, City possible attributes of the Accum! entity set are Account no, Balance. Each entity has a value for each of its attributes. For instance, a parti Customer entity may have the value ‘C101’ for attribute Customer | far Customer name, and Bombay’ for City. For cach altribute, there is set of permitted values, called the domain, value set of thal attribute. The domain of attribute Customer_name might set of all tent strings of a certain length. Types of attributes Attributes are Classified as + Simple © Composite Single-valued Maulti-valued Derived Simple attribute i A simple affrituée is an attribute composed of a s component with an independent existence. Simple attributes can not be f subdivided, Examples of simple attributes include Roll_No, Salary etc. if) Composite attribute ; An attribute composed of multiple components e: wilh an independent existence is called a composite aitribute. + Examples of composite atiributes are : 1) Name, which is composed of attributes like first name, middle name last name. 2) Address, which is composed of other components like Street, City, Pi ii) Single-vaiued attributes : A single-tuiuied attribute is one that holds a sin value for a single entity. Examples are Room no, Customer_id, Single-vala attributes are also called as atomic attributes. iv} Multivalued attributes : A multioalued afribute is one that holds mult values for a single entity. For example, a student entity can have mull ‘values for the Hobby attribute such as reading, music, painting. ¥) Detived attribute : A derived atirthte is one that represent a value U derivable feom the value of a related attribute or set of attributes. For exa the age attribute can be derived from the date of birth attribute. Database Management Systems 4225 Introduction 3) Relationships and Relationship Sets [May-07, 6 Marks) th relationship expresses an association among several eae: A relation a sel of relationships of the same SP For example, consider two entities Person and Compary 25 shown in Fig. 19. The selationship Works-for represents association between Person and Company. This is 2 binary relationship set TS oo Fig. 1.9 An E-R diagram > Entity role “The function that an entity plays in» relationship is called that enbty’s role. A role is one end of an association. Consider following Fig: 1.10 ()- snpoyee ] Fig. 1.48 (a) One-to-che relationship my entlty It A is associated with any mumber of entities (zero of in B, however, can be associated wish at most one entity in A, ‘Database Management Systems 1-29 Introduction xample + Many employees works for a company: ‘Tis relationship is shown by mmany-to-one as given below. Fig. 1.49 Many-to-one relationship ix) Many-to-many An entity in A is associated With ony number (zero ot more) of entities in B, and an enlity in B is associated with any namoet (ero of more) of entities in A. ‘Fig. 1.20 Many-to-many relationship Exawple + Employee works on umber of projects and. project is handled by sumbes of employees. Therefore, the relationship between Employee and project is many-to-many as shown below. Fig. 1.21 Many-to-many relationship 2) Participation Constraints There are two types of participation constrains « J) Total participation : The participation of an enkity 5 in a relationship set R is said to be otal i every entity in E participates in at least one relationship in R. f@ Panticl participation : if only some entities 19 F participate in rolationships in R, the anticipation of entity set F in relationship Fi said to be partial For example, we expact every Loan enlity to, be elated to at least one Customer Grough the Borrower relationship. Thereio‘e, the participation of Loan in the edatisnchip set Borrower 's total. While, a bank customer TAY or may not have a nan, Therefore, the participation of Customet in the Borrower relationship is parti Databaso Management Systems 1-30 Introduction, 1.11.3 Keys [Dee-02. 04, 5, 06, 2 Marks; Mey-08, 8 Marks; May-G8, 2 Marks} A Key allows us to identify a set of attributes and thus distinguishes entities from each other. Keys also help uniquely identify relationships, and thas distinguise relationships from each other. Different types of keys are : + Superkey * Candidate key + Primary key + Foreign key 1) Super key : A superkey is a sest of one or more attributes that allows us ta identify. uniquely an entity in the entity set. For example, the Roll_No attribute of the entity set ‘student’ distinguishes one student entity from another. 2) Candidate key = A superkey may contain extraneous attributes and we are often interest in the smallest superkey. A superkey for which no subset is a superkey i called a candidate key. For example, Sludlent name and Student street, are sufficient to uniquely identify one particular student. Hence, Roll_No, and (Student Name, Student _strect] are candidate’ keys. “Although the altsibutes Roll_No and Student Name together can. disting Customer entities, their combination does not form a candidate key. Since the attribu Roll_No alone is a candidate key. 3) Primary key : Il is a candidate key that is chosen by the database designer as the Principal means of identifying entities within an entity set. For example, Roll_No is 4 Primary set of ‘student’ entity set The primary key should be chosen such that its attributes are never or rarely, changed. For instance, the Address field of a Pe should not be part of the primary key, since it is likely to change. Social security on! the other hand, are guranteed (o never change. 4) Foreign key : An attribute or set of attributes, within one relation that matches candidate key of some (possibly the same) relation. For example, the inclusion of Branchno in Branch and staff relation links each branch to the details of staff working at that branch. In the Branch relation, Brangh_no is primary key. However, in. the staff relation the Branch_no attribute exists to match staff to the Branch office they work in. In the staff relation, Branch_no is foreign key. 4 Entity Relationship Diagram [De-05, 4.Marke} The overall logical structure of a database can be expressed graphically using ER 5. Such a diagram consists of the following major components. Represents entity ts Roprasenis stribvlet 5) Bamands Represents relalonshio cots Links atvibutes to enbiy sets S)Lines ‘ently set6 19 relationship sets 5) Double ellipses Riopresente mutivalued alteoutes 6) Dashes elinses > ‘Represents derived stbibutes TiDovble rextangies Represents weak enbly sets Doub Reprasenis total paniopation of oe ‘aneniy in a rolabonship Fig. 1.22 ER diagram symbols Fig. 123 shows an FAR diagram for banking system. Tt consists of two =, Customer and Loon related through binary relationship set Borrower. The Fig. 1.23 E+ diagram corresponding to Customers and Loans Databaso Management Systarns 1-32 attributes associated with Customer are Customer id, Customername, and Customer_address. The attributes of Loan are Loan no and Amount. 1) Mapping Cardinality Cardinality in E-R diagram that is represented by two ways : 3) Directed line (3) 4i) Undirected line (—) & ‘Types = 2 One-tovone relationship : Following Fig. 1.24 represents one-to-one relationship between two entities : “Manager” and ‘Department’, related trough 2 binary relationship ‘Manages. SSD Fig. 1.24 Onesto-one relationship 2) One-to-many relationship : Following Fig. 1.25 shows one-to-many relations Detween entities : ‘Department’ and ‘Employee’, related through bi aelationship ‘Tas’ Employee Fig. 1.25 One-to-many relationship 3) Many-to-one relationship + Following Fig. 126 shows many-to-one relationship between entily ‘Students’ and ‘GEM’, relates through binary relationship ‘Have’. T interpretation is, many students have one GFM (Guardian Pa Database Management Systems Aas <] ae Fig. 1.26 Many-to-one relationship 4) Many-to-many relationship = Following Fig, 127 shows many-to-many relationship between enlity sets ‘Employee’ and ‘Course’ related through binary relationship ‘Joins’ ee Fig. 1.27 Many-to-many relations 2) Dependency [Moy-08, 2 Marks] ® Existence Dependencies If the existence of entity x depends on the existence of entity y, then x is said to be existonce dependent on y. If y is deleted, so is x. Entity y is said to be a dominant entity, and x is said to be subordinate entity Consider the entity set ‘Loan’ and the entity set ‘Payment’ that keeps information about all the payments that were made in connection to a particular loan. The Payment entity set is described by the attributes Payment.no, Payment date and Payment_amount, We form a relationship se Loan-payment hetween these two entity sets, which is oneto-mmany from Loan to Payment. Every Payment entity must be sssoriated with a Loan entity. If a Loan enlily is deleted, then all its assodated Payment enlilies siust also be deleted. In contrast, Payment entities can be deleted fom the database without affecting any loan. The entity set Loan is therefore Payment ns > Soi) Fig. 1.28 (a) Existence dependency Database Management Systems dominant entity set which is also called as slrong entity set, and the entity set Baym '§ subordinate which is also called as weak entity eet, in Loan-payment relationship. ‘The Fig. 1.28 (@) shows the dominant entity set ‘Loan’ and subordinate entity ‘Payment’ connected by relationship ‘Loan-payment » Definition = Strong and woak entity 9¢ts Entities are classified as being strmg or weak entity types. An entity that SER’ Gependent on some other entity is called a maul eutty bype. An entity set 0 ‘which weak entity set depends, is called strong emiity set. For example, Fig. 1.28 (b) shows weak entity sct ‘Parent’ which depends on si entity set ‘Employee’. ee CEA > Cie sae ete > Cima Fig. 1.26 (b) Strong and weak entitios 3) Representation of Role Fig. 1.29 E-R diagram with role indication Database Management Systems 4) Sample E-R Diagrams {) ER diagram with an atiribute attached to 2 relationship set Fig. 1.30 E-R diagram with an attribute attached to a relationshin set Tf a relationship set has some attributes associated with it then we Tink these attributes to that relationship set. For example, in Fig. 1.30 the accese-date attribute is attached to the relationship set depasiter to specify the most recent date en which a customer accessed that account. Fig. 1.31 ER diagram with composite, multivalued and derived attribute Database Management Systems 1-36 Intreduction As shown in Fig. 1.31 ‘Name’ is @ composite allzibute with component attributea ‘name, Lastname. Similarly Address is also a composite attribute with Sormenent alinirules Street, City, State, Pin. Ph nw is a multivalued attribute and Age is a derived atuibate. 4H) Total participation of an entity set in a relationship set < asia Sn- Fig. 1.32 Total participation of an entity sot in a relationship set a> ent > As shown in Fig. 1.32, a double line from Loan to Borrower indicates that eachll ‘Loan must have at least one associated customer. iv} Cardinality timits on relationship sets Fig. 1.33 Cardinality limits on relationship sets As shown in Fig, 1.83, the edge between Custamer and Borrower has cardinality Sorsitaint 0 ...* indicates that Customer has zero or more loars. The constesint cain the edge between Borrower and Loan (1. t) indicates that a loan must have coe customer associated with it. ¥) ER diagram for Book Ciub Hg. 130 shows an E-R diagram for Book Club. The book club has members, The ‘book club sells books to its members. The embers places orders for books, which the book club fulfllx. Each order containe one ‘er more than one book. The books are waitten by author(s). ‘The Publisher publishes: the book. Database Management Systems: Fig. 1.34 E-R diagram of the Book Club An author can write more: than one book and a book can have more than one author. A boak is published by a publisher, but a publisher publishes many books. A ‘member can place more than one order. He also can choose not to place an order. The book club sells many books. The book ciub exampte is converted into an E-R diagram and is shown in Fig, 1.34 Fig. 1.35 vil) ER dlagram for insuray (2) ER diagram for Banking Enterprise nea database Database Management Systems 4-39 Introduction 4.41.5 Extended E-R Model “The ER model that is supported with the additions! gemantic concepts is called the extended entity relationship model or EER sodel ‘The EER model includes all te concepts of the original ER model together with the following additional ‘eoncepts= = Specialization = Generalization Aggregation 4) Specialization sspeiaication tx the provess of designating SUPEFOUPInE within an entity set.” specialization is a top-down process. Consider an entity set Person, with attributes Name, Street, and City. A Perso may be further classified as one of the following = Customer + Employee Each of these Person types is described by @ set of attributes that includes all the saibstes of enkty set Person plus additional altsbotes. For example, Customer cates may be farther decenbed by Customer lé ‘and Employee entities by Employee code and Slary- Fig. 136 shows specialization, which is represented by triangle The lable ISA sande for "is a, and represents, for exainple, that Costomnet ‘ig a” Person. ‘The ISA selationship may also be refersed t0 28 & superclase-qubclass relationship. Gee Fig- 136 on-next page) 2) Generalization «Generalization: the process of defining a more general ently (FPS from a set of more sce‘ialized entity types” Generalization is a bottom-up approndh This approach resus the identification ef-s generalized superclans from the original subclasses, Consider that the attributes of ‘Customer’ enlily a6 Customer_id, Name, Street, City ed an ‘Employee’ entity atti Street, City and Salary. Thus, ue entity sets Employee and Customer jules in common. This ‘commonality can be xp ization which is a containment relationship Reprise: between 2 Higher level entily Set andone or Sm lower-level entity sets whe shown in Fig. 136 Person is 2 higher-level entity set and Customer and Employee fan lower-level entity sets. in other words, Person is 2 superclass if customer and ‘Employee are subclasses. Secreta Flours worked) Fig. 4.36 Specialization and generalization > Generalization constraints Constraints in specialization and generalization allow us to capture some of the important business rules that apply to the relationships. 2) One type of constraint involves determining which enlities can be members of a ‘given lower-level entity set. Such membership may be one of the following : * Condition defined : In conditiondefined lower level entity sets, membership 5s evaluated on the basis of whether or not an entity satisfies an explicit condition ot predicate. For example, assume thot the higher-level entity set Account is having attribute Account type. Only those entities that satisfy the condition Account type = “Savings account” are allowed, to belong to the lower-level entity set “Savings_account’ All entities that satisfy the condition ‘Account_type = “checking account” are included in checking account, User defined : These types of canstraints are defined by user. Fox example, {et _us assume that, after 3 months of employment bank employees arc assigned to one of four work teams. We therefore zepresent the teams 45 four lowerlevel entity ‘sets of the higher-level Employee entity set. A given Employce is assigned to one of the four teams by incharge of the teains, ‘Database Management Sysiems 11 Introduction 4B) A second type of constraint relates to whether or not entities may belong to more than one lowerdevel ealily set within a single generalization. The lower-level entity sets may be one of the fallewing + Disjeint = A disjcintness constraint requires that an entity belong to only onc lowerlevel entity set. For example, an Account entity may be either Saving_accoun! or Checking, account It satisfies fust ene condition at a time. = Overlapping : in overlapping generalization, the same entity may belong te more than one lower-level entity set within a single generalization. For example, a single inanager may participate in more than one work tearm, ‘Another example is, assume from Person, two entities Customer and Employee, fare derived. The generalization is overlapping if an Employee can also be a customer. OA final constraint, is a completeness constraint on a generalization/specialization, which specifies whether or not an entity in the higher-level entity set must belong to ‘at least one of the lower-level entity scts within the generalization /specialization. This, ‘constraint may be one of the following 4+ Total generalization or specialization : Hach higher-level entity must belong, to a lower-level entity set. Partial generalization or specialization : Some higher-level entities may not belong to any lower-level entity set. Partial generalization is the default, We can specify total generalization in an E-R diagram by using a double line to connect the box representing the higher-level entity set to the tangle symbol. For example : Employees are assigned 10 = team only after 3 months on the job. Some Employee entities may nol be members of any of the lower-level team entity ‘sets, We may characterize the team entity sets more fully as 2 partial, overlapping specialization of Employee. ‘The generalization of Cheeking account and Savingsaccount into Account fs 2 total disjoint genezalization 3) Attribute Inheritance “9 exucial property of the higher and lower-level entities created by specialization and. generalization is attribute inheritance”. The attributes of the higher-level entity sets are said to be inherited by the lower-level entity sets. For example, Customer and Employee inherit the atributes of the Person, Thus, Customer is described by Name, Street, City and with additional attribute Customer_id. Similarly, Employee is described by Name, Street, City and additional attributes Employee code and Salary. Database Management Systems 4) Aggregation [May-06, 2 Nor ‘One limitation on E-R model is that it eannot express relationships among) relationships. ‘Consider a quaternary relationship Manages between Employee. Branch, Job, and. Manager. Using the basic E-R inodéling constructs, we oblain the E-R diagram shown below, Fig. 1.37 ER diagram with redundant relationships ‘There is redundant information in the resultant figme, since every Employes Branch, Job combination. in Manages is also in Works_on. ‘The best way to model above situation is to use aggregation. Aggregation is abstraction through which relationships are treated as higher-level entities. Thus, relationship set Works.on relating the entity sets Employee, Branch and Joo considered as a higher_level entity set called Works_on. We can then create 3 binary: yelationship manager between Works_on and manager to represent who star what tasks. base Management Systems Fig. 138 shows ER with aggregation. [see] = Fig. 1.38 E-R diagram with aggregation © Altemative E-R Notations Fig. 1.39 Symbols used in the E-R diagram Database Management Systems 4-48 Introd 4.41.6 Reduction of an E-R Schema to Tables We can represent a database thal conforms to an E-R database schema ‘ellection of tables. For each entity set and for each relationship set in the datal there is a unique table to which we can assign the name of the corresponding set of relationship sct Hach table has multiple columms, each of which has « name, Both the E-R model and the work! enterprise. convert an E-R design inta a relational desig. ‘The constraints specified in an E-R diagram, such as primary constraints, are mapped to constraints on the tables generated frum the E.R diagram 1) Tabular Representation of Strang Entity Sets Het E be a strong entity set with descriptive attributes ae .a3 yay. We repre this entity by a table called E with n distinct column, each of which comespands ‘one of the attributes of E. Each now in this table corresponds to ane entity. of entity set E For example, consider an entity set ‘Student’ with attribute ! Roll No and Ni We represent this entity set by a table ‘Student’ with two columns ‘Rell Not “Name’ as shown in Fig. 1.40. Fig. 1.40 The studont table The row, (2001, John) in the table Student, means the Roll No 2001 and na John. We can add new rows and also delete or update existing rows 2) Tabular Representation of Weak Entity Sets Let A be a weak entity set with attibutes @1,a3..:my. Let “B’ be the al eniity set on which A depends. Let the primary key of B consist of attibul hiyby, We represent the entity set A by a table called A with one column cach attribute of the set. rea2 Je fbr bet fF ‘Database Management Systems 4-45 Introduction For example, consider an entity set “Tnuwaction’ with attributes Transaction date, Debitamount, Creditamount and Balance. It depends on. entity set ‘Account’ with paimary key Account-no. Thus the Transaction table is represented by columns ‘Account-no, ‘Transacion-date, Debitamount, Credit-amount, Balance as shown in Fg 141, ‘Account -no | Transaction - date | Debit - amount |Cregit - amount} Balance 2an2ran0a 100 a 2300 srorzo01 a 1300 ovoyz002 200 1500 e220 8 2000 Fig. 1.41 A Transaction table: 3) Tabular Representation of Relationship Sets Let R be a relationship set, Let ,dzer,tiy be the set of attributes formed by the union of the primary keys of each of the entity sets participating in R, and let the descriptive attributes (if any} of R be hy b> sty. We represent this relationship sct by table called R with one column for each attribute of the set it meetin FO (BL Boren For example, consider the relationship set Depositor. In Fig. 142 with descriptive attribute accose-date. This relationship set inwulves two entity sets. + Customer, with the primary key Customer-id _® Account, with the primary-key Acrount-ne Thus, the Depositor table has three colurnns as shown in Fig, 142 ‘Aceount_no Access. date ‘80001 vorse2000 Ante 3102001, altos fe sania Fig. 1.42 The Depositor table > Redundancy of Tables Consider two entity sets Loan and Payment, which are link relationship Loan-payment with no descriptive atmbute. The w Database Management Systems, 1-48 depends on entity set Loan. The primary key of Payment is (Loan_no, ‘since Loan-payment table has no descriptive attributes, it would have two column jLean_ne, Payment_noj. Every (Loan_no, Payment no] combination in Lean paymer would also be present in the Payment table, and vice versa. Thus, Lean-payment tab is redundant. In general, the table for the relationship set linking a weak entity set § its corresponding strong entity set is redundant and does not need 10 present a ‘representation of an ER diagram, > Composite Attributes ‘We handle composite attributes by creating 2 separate attribute for each of component attributes ; we do not create a separate column for the composite altribu itself Suppose Address is a composite attbute of entity set Customer, and the components of Address are Street and City. The table generated from Customer would) then contain columns Address street and Address city ; there is no separate. column for Address. » Mulfivalued Attributes. Consider an entity set Employee with multivalued attribute Dependent name. For, such multivalued attribute, create a separate table as Dependent. info with attributes Dependent name, and Employee.id which is the primary key of Employee entity set } Tabular Representation of Generalization There are two different methods for transforming to a tabular form an E-R that includes generalization. Consider the generalization shown in Tig. 143 where Account| is a higher-level entity, while Saving account and Checking account are lower-level entities. are mal Fig. 1.43 E-R with generalization 1. Create a table for the higher-level entity set. For each lower level entity set, qreste separate table that includes columns for cach of the attributes of that entity set plus a column for each attribute of the primary key of the higher-level entity set. Thus, for E-R diagram in Fig. 143 we have three tables «Account, with attributes Acc ao and Balanee reer Ta P| = Saving account, with attributes Acc no, Interest rate. = Checking. account, with attributes Ace_no and Overdraft amount if the generalization is disjoint and complete, that i, if mo entity is 2 member of two lower level entity acts directly Below 2 higher-level entity set, and if every entity in the higher-level entity set is also a member of one of the Jower-level entity sets. Then, do not create toble for higher level entity set Instead, create separate table for each lower-level entity sets that includes ‘column for cach of the attributes of that entity set plus a column for each attribute of the higher-level entity set Then for E-R diagram in Fig. 143, we fhave two tables + = Saving account, with attributes Acc no, Balance and Interest_rate. = Checking account, with attributes Acc_no, Balance and Overd:afi_amount. ir Representation of Aggregation E-R diagram in Fig. 1.38, the table for the rélaionship set Manages between the of Workson and the entity set Manager includes + eslumn for each in the primary keys of the entity set Manager and the relationship set Te would also include the descriptive attributes of relationship set, if any The lerm relational dataBnse was originally defined by Edgar Codd at IBM Almaden earch Center in 1970, Relational databases, as implemented in relational databsse ent syslems, Rave become 2 predominant choice for the storage of mation in new databases used for financial records, manufacturing and logistical personnel data and, much more. In the relational database, the user only needs to understand the logical stractare dala, not how it is physically stored. In this database. data is represented in simple “eeodimensional tables (relations), which consist of zows (tuples) and columns (etsbutes). A relational database is simply 4 collection of lables. Relational database theory uses a set of mathematical terms, which aze roughly equivalent to SOL database terminology. The table 1.1 summarizes some of the most important relational database terms and their SQL database equivalents. ew, query resus, reset sot ‘caluma Table 4.3 Relational terms and thair SQL equivalents ® Relational Database Basic Concepts ‘* Relations or Tables A elation is defined as set of tuples that have the same attributes A tuple Usually represents an object and information about that object. Objects are typically Physical objects or concepts. A relation is usually described as a table, which 2 organized into sews and columns. All the data referenced by an atiribute are in the same domain and conform to the same constraints. Applications access data by specifying queries, which use operations such as select te identify tuples, project to identify atinbutes, and jain to combine relations. Kelations ‘an be modified using the insert, delete, and update operators. New tuples can supply splict values or be derived from a query. Similarly, queries identify tuples for Updafing or deleting It is necessary for each tuple of a relation to be uniquely identifiable by some combination (one or more) of its attribute values. ‘This combination is referred to as the primary key © Base and derived relations im a zelational database, ali data is stored and accessed via relations. Relations that Store data are called “base relations’, and in implementations are called "tables". Other felations dio not store data. but are computed by applying relational operations 19 other relations. These relations are sometimes called ‘derived relations’. In implementations these are called “views” or ‘queries’. Dezived relations are convenient in hat though they may grab information from several relations, they act as a single relation. Also, derived selations can be used as an abstraction layer + Tuple!RecordiRtow A record holds all the information about one item or subject. Conceptually, if you ullected business cards from 50 people, all 50 cards would represent a table and the information on any one business card would represent one record. In a database ‘able, each row is a record / tuple. dit thai can you are works = Primary Ke A primagy identifies each table it i Kol student in the ‘Database Management Systems = Field/(Column ‘A field holds one piece of information about an item or subject. Since a field is column in database table; some database experts prefer to just use the word column, Jn the Student table there are fields for Roll No, Nome, Address ete. In a relational database, the relationships are maintsined by having matching fields in two tables. For instance, the Student table and the Result table share the Roll_No field, thus allowing the two tables to be linked and data to be pulled from the twa tables together. = Domain A domain describes the set of possible values for a given attribute. Bectuse 3 omuain constrains the attribute's values and name, it can be considered constraints Mathematically, attaching a domain to an attribute means that ‘all values. for this, tribute must be an element of the specified set.” The character data value ‘ABC, for instance, is not in. the integer domain. The integer value 123, satisfies the domain constraizt. + Constraints Constraints allow you to further restrict the domain of an attribute. For instance, 2 constraint can restrict a given integer allsibule to values between, 1 and 10. Constraints provide one method of implementing business rules in the database. SQL implements constraint fonctiomality in the form of check constraints. Gonstraints restrict the data that can be stored in relations. These are usually déGned using exprassions that result in a boolean value, indicating whether or not the dala satisfies the constraint. Constraints an apply to single alteibutes, to a tuple (restricting combinations of attributes) oF to.sn entire relation. Every attribute has an associated domain. It is called as domain constrainis. ‘The two poncipal rules for the relational model are known as entity integrity and referential nay. # Data Type Every field in a database table is assigned a data type, which describes the kind of data that can be stored in the field. Data types vary depending on the database system you are working, in. » Primary Key A. primary key is a field (or possibly multiple fields used together) that uniquely ‘identifies each record in the table from every other record in the table. In our Smdent ‘able it is Roll No. Each student has an Roll_No that is different from every other student in the table. Primary Keys are essential in a relational database. Database Management Systems + Foreign Key A forcign key is a reference to a key in another relation, meaning that the referencing tuple has, as one of its attributes, the values of a key in the refere tuple. Foreign keys effectively use the values of attributes in the referenced relation restrict the domain of one or more attributes in the referencing relation. A foreign key could be described formally as: "For all tuples in the referenci relation projected over the referencing attributes, there must exist a tuple in referenced relation projected over those same attributes such that the values in each the roferencing attributes match the corresponding values in the referenced attributes! For example, the Subject_id, primary key of Subject table, is used as foreign key in ‘Time_Table table « Stored Procedure ‘A stored procedure is a high-end database tool that adds programming power the database. A stored procedure is executable code that is associated with, generally stored in the database. Database administrators will often create sl procedures to handle inserfs, edits, and updates of records. The front- programmer, then only needs fo call the stored procedure ta accomplish th fonctions. It makes the programming code simpler and helps protect the datab from problems caused by program bugs. @ indices An index is one way of providing quicker access to any combination of attributes on a relation. Queries that filler using those attributes can find matching tuples randodtly using the index, without having to check each fuple in turn. Relational databases typically supply multiple indexing techniques, ‘of which is optimal for seme combination of data distribution, relation size, typical access pattern. Different indexing techniques are B-Tress, B+ trees. «Relational operations Queries made against the relational database, and the derived relvars in. database are expressed in a relational calculus or a relational algebra. in his origi relational algebra, Codd introduced eight relational operators in two groups of fi operators each. The first four operntors were based on the traditional mathematical operations: © The union operator combines the tuples of two relations and removes all duplicate tuples from the result, The relational union operator is equivalent to the SQL UNION operator. Dstabars Management Systems Intreduetion + The intersection operator produces the set of tuples that two relations share in. common. Intersection is implemented in SQL in the form of the INTERSECT ‘operator. ‘The difference operator acts on two relations and produces the set of tuples from the first relation that do net exist in the second relation. Difference implemented in SQL in the form of the EXCEPT or MINUS operator. “The cartesian product of two relations is a join that is not restricted by any ‘criteria, resulting in every tuple of the first relation being matched with ‘every tuple of the second relation. The cartesian product is implemented in SQL as the CROSS JOIN join operator. ‘The remaining operators proposed by Codd involve special operations specific to ‘selationat databases: * The selection, or restriction, operation retrieves tuples from a relation, limiting. ‘the results to only those that meet a specific cziteria, ie. a subset in terms of set theory. The SQL equivalent of selection is the SELECT query statement with a WHERE clause, ‘The projection operation is essentially a selection operation in which duplicate tuples aré removed from the result, The SQL GROUP BY clause, or the ‘DISTINCT keyword implenenied by some SQE dialects, can be used to ‘remove duplicates from a result set. ‘The joi operation defined for relational databases is often refernd fo as & cnatural join. In this type of join, two relations are connected by their -coitaton attibutes. SQLs approximation of a natural join is the INNER JOIN join operator. ‘The relational division operation is a slightly more complex operation, which invelves essentially using the tuples of one relation (the dividend) to ‘partition @ second relation (he divisor). The relational division operator is ‘effectively the opposite af the cartesian product operater (hence the name). ‘= Normalization Nonnalization was first proposed by Codd as an integral part of the relational ‘model. It is used to eliminate the duplication of data, which in turn prevents data manipulation anomalies and loss of data integrity. The most common. forms of ‘normalization applied to databases are called the normal forms. Relational Model Relational Mode! Dee-08 , 2 Mork geisSonal mode! was introduced by Dr. EF. Codd in 1970 and has evolved “rough a series of writtings. The relation at model represents data in the © dimensional tables. Each table represents some real world entity, or thing. ton of data into relational tables is known as the logical view of the understanding of the relational model is necessary to cffectively use Gatabase software such as Oracle, Microsoft SQL Server, Sybase, which are the relational model. cteristics of Relational Model “Tee relational model climinated all parent child selationships and instead Sepcesented all data in the database as simple row/column tables of data values. "A gelation is similar to a table with rows/columns of data values. ‘ech ible is an independent entity and there is no physical relationship ex tables. ‘ “Mies data management systems based on the relational model have a built-in ort for query languages like ANSI SQL or QBE, These queries are English constructs that allow adhoc data manipulation froun 2 table, Beistional model of data management is based on set theory. “Tee user interface used with relational models is non-procedural because ‘acl what needs to be done is specified and not hew it hes to be dene. Database Management Systems 2-2 Relational mi 2.1.4 EF. Codd’s Laws for a Fully Funetio: Management System ER. Codd’s taws for a RDBMs are given below. ‘D Relational database management + ‘ses only its relational capabilities to 2) Information representation + All ink Tepresented only Up the database 9) Logical accessibility : Every data item value stored in a ral 7 celle by stating: the name of the table it ie stored jn, the name of the Gpluam under which it is stored and the value of te primary key that defines the row in which it is stored, ® Representation of null values : Nal Relational Database ‘A Telational database management sys manage the information in its database “tiption of 2 relational database ig Same manner as ordinary data facilities of the relational database man. maintain database description. ©) Data language : A relational DEMS may si describing deta and accessing the database 7) View upaatability : Any vi ‘This is done so that the agement system itself can be used to sPport many types of languages for fables, that are theoratical relational DEMS, operation as wel 9) Physical independence : Changes made Teptesentations or access methods application programs. Management Systems 2-3 Relational Model 42) Database distribution’: The database language implemented PY ‘the RDBMS supports the ability to distribute the database without requiring: changes to be ‘made to epplicaion programs. 35) Non subversion’: If the RDUMS supports eciliies that allows pPPHE MIN [programs to operote on the tables 2 row at a tims, an application program ing this type of database access is prevented from by Passing entity iningsity oe referential integrity constraints that are defined for the database 4.2 Principle Components of Relational Model ‘The rclationsl model consists of fellewing three basic components = + Data structure = Data integrity + Data manipulation 2:42: The Relational Dats Structure [Doe-04, 2 Marks} Bee iagtiasl ata. stauchane. w show th Fig, 2.0 TEP tase on employes ‘relation. Een ern oe Cepatent ae Emp no E0506 | essen eT6 mean 4 | eae Open | eau8r bamianance eee deer — Fig. 2.4 Relational date structure If we think of a relation as a table, then. a tuple corresponds "> 2 17 of such a toble and an attribute (0 a column. The number of tuples is called the cardinality and the maumber of attmibutes is called the degres, and a domain is 2 pool of ‘values, from TREh the values oF specific attributes of specific relations art taken. The domain Fig. 22 Structural terminology summary 24.22 Relational Integrity Risstity ‘constraints provide a means of ensuring. that Gatabase by authorized uscrs do not result in a lose of cbte ‘The main types of integrity constraints are : + Domain constraints + NULLS * Enterprise constraints + Entity integrity constraint. They are red into the database fields. {Mey-03, 08 , 2 darks; Dec-05, 5 Marks; May-06, 3 tion for a given set of attributes also appeats for relation. This is called referential integrity » Roferontial integrity in the E-R model As shown in Fig. 23, an Let nary relationship sct R, relating entity sets Dj. F, denote the primary key of £. The attributes of the relation scheme fee Peagomaltip set R include Kj ke UU. Each Ke in the scheme for R is 9 foreign key that leads to a referential integrity constraint L, Fig. 2.3 An nary relationship sot “Another source of referential integrity constraints are weak entity sets. The relation creme for a weak entity set must include the primary key of the entity set on which Gepends. Thus, the relation scheme for each weak entity set includes a foreign key leads to a referential integrity constraint Referential integrity in SQL Using SQL, primary key, candidate key, and foreign key are defined a5 part of the mate table statement as given below = cample : create table Deposit (Branch_name char(15), ‘Ace no char(10), Cust mame char (20) not mall, ‘Balance integer, primasy key (Ac¢_0, Cust_name), foreign key (Branch_»ama) references Branch, foreign key (Cust_name) references Customer) ; 3 Nulls [May-06, Dec-07, 2 Marks] | -ywull represents a value for an attribute that ic currently unknown or is not “applicable for this tuple.” ‘A ull can be taken to mean the logical value unknown, It is a value that is:not szoplicable to a particular tuple. Nulls are a way to deal with incomplete or exceptional data. However, a null is neither a zero numeric value nor a text string filled with spaces. (Other integrity constraints ace : entity integrity #nd enterprise constraints. ‘Database Management Systems 2-6 4) Entity Integrity [Bee-05, 5 Marks; May-06, 3 “In a base celation, no attribute of a primary key can be null” * primary key is ued to identify tuples uniquely. This means that no subset the primary key i sufficient to provide unique identification of tuples. Th Primary Key should net be null: For example, as Branch no is the primary key of Branch relation, we should not be able to insert a tuple into the Branch relation wi nll for the braneh no attribute §) Enterprise Constraints ‘These are additional rules specified by the users or database administrators a database. It is also possible for users to specify additional constraints that the data + For example, if limit on number of staffs working at a branch is 20, then user must be able to specify it and expect DBMS to enforce it. Im this case, it not be possible to add a new staff at that branch. 2.4.23 Data Manipulation The manipulative part of the relational inodel consists of a set of operators collectively as the relational algebra together with relational calculus. 2.1.3 Advantages of Relational Model ‘The major advantages of the relational model are * Structural independance = When it is possible to make change to database structure without affecting the DEMS's capability to actess data, can say thal structural independence have been achieved In relational database, changes in the database structure do not affect the access. So relational database has structural independence Conceptual simplicity : The relational database model is simpler at conceptual level. Since the relational data model frees the designer from Physical data storage details, the designers can concentrate on the lo View of the database. Designy implementation, maintenance and usage case : The relations database model achieves both data independence and structus independence making the datubase design, maintenance, administration and usage much easier than the other models, Good for ad-hoe requests {It is simpler to navigate ‘Greater flexibility. Management Systems 4.4 Disadvantages of Relational Model Significant hardware and software overheads. Not as good for transaction process modeling as Aierarchical and network models. May have slower processing times than hierarchical and network models. y The Catalog [otoy-03, 04,2 Marke] Data dictionary is a repository of information describing the data in the database, that the metadata or the ‘dria about the data.” The DBMS system catalog is one of the fundamental components of the system. “Many of the software components that rely on the system catalog for information. For ‘sample, the authorization control module uses the system catalog te check whether ‘eser has the necessary authorization to carry out the requested operation. To perform this check, the system catalog has to store = ‘+The names of users authorized to use the DBMS. ‘The names of the data items in the database. «The data items that each user can acess, the types of access allowed = for example, insert, update, delete or read access. As another example, the integrity chock module uses the system catalog ty check that the requested operation satisfies all necessary integrity constraints, To perform this check, the system catelog has to store - © The names of the data items in the database, + The types and sizes of the data items + The constraint on cach data item. Data dictionary system can be classficd as active or passive. An active system is ‘always consistent with the database structure, because it is maintalned sutomatically by the system. On the other hand, a passive system may not be consistent with the database, as changes are initiated by the users. If the data dictionary fs part of the DBMS, we refer to it as an integrated data dictionary. A stand alone data dictionary ‘has two its own specialized DBMS. 23 Types ‘The data types are a dassification of a particular type of information. Tt is easy for ‘programmer 10 distinguish between different types of data. Relational model supports following data types: Database Management Systems, fe 4) Character (n) This datatype repens «feed long sting af exe's’ characters where 31 speater than zero and should be an integer. Example ¢ ame character (10) 2) Varchar (n) or character varying (A) ses data aype represents a varying length ng, whose mania Legt huracters. ‘Example : ‘Name varchar (n) 3) Numeric (P, 4) “ Tits dat type nmpreseny = end murber 17 Giga ae Sign with ail decimal point “q" digits froma the sign. Both “p’ and ‘a! ave inteBors ‘Example = Prige numeric (6,2) 4) Integer ‘An integer represents a signed integer decimal or binary- Example < Rol No integer (3) 5) Small int va small integer is © machine independent subset of the inteper domain IYP® Example = ‘Roll_No small int (3) 6) Real, double precision Floating-point and double-precision floating point numbers with machine dependent precision. 7) Float (n) ‘A floating point number, with precision of atleast digits Example + Rate float (5,2) ‘A calender date containing a (four-digit) year, month and day of the month, Date_of_bisth date Time ‘The time of day, in hours minutes and seconds. A variant, Hme (P) can be used to Sfy the number of fractional digits for seconds (the default being 0}. Pag ‘Anivaltime time Timo stamp ‘A combination ef date and time. A variant, timestamp (P}, can be used to specify number of fractional digits for seconds. Date and time values can be specified like this = date ‘2005-04-25' time ‘09: 10: 25) time stamp ‘2005-04-25 08 : 25 : 20.45" Dates must be specified in the format - year followed by month followed by day, les shown. The seconds field of time or timastamp can have a fractional part, as in the mestamp above. 2.4 Keys Key is a field or set of fields that uniquely 1D tuples in a relation. For evary relation, we need a key. Sometimes key takes several ficlds In the extreme case the entire tuple # also used a5 a key. > Different types of keys in relational model are: © Super key : It is a field or set of fields that uniquely TDs tuples for # given relation, ‘© Candidate key : It is minimal superkey. + Primary key : The candidate key chosen as the principal means of identifying tuples. Database Management Systems Relational Medel + Alternate keys : One of the set of candidate keys is chosen to be the prithary key, the others are altemate keys. > References between tables + Tables often refer to each other. + We sepresent this by storing @ key value from one table in another other table. ; The primary key of onc table that is uscd in another table i called foreign = “ » Foreign Key +A foreign key is an attribute or combination of attributes in relation R2 Whose values must maich the primary key values in RL. In referring to the RI tuple by its primary key in R2, you must be sure it exists in RI. For example, the Subject id, primary key of Subject table, is used as foreign kep in Time_Table table. Declaring that an attribute is a forvign key is another kind of (Gnter-relationsl) integrity constraint called a foreign key constraint, or referential constraint, or inclusion dependency, If you have a foreign key, it should be true thal the attribute (s) it refers to are the primary key for the other relation the values actually exist in the other relation, 2.5 Relational Algebra A query language is a language in which a user requests information from databaso, These languages are usually on a level higher than that of a ‘programming languages. Query languages can be categorized as - |) Procedural languages In procedural language, the user instructs the system to perform a sequence operations on the database to compute the desired result, i) Nonprocdural languages In a nonprocedural language, the user describes the desired information witha giving a specific procedure for obtaining that information. tion to Relational Algebra [Mey-04, Doe 57,9 Marka; Moy 06, 2 Marks; Dec08, 10 marks] “The relational algebra is a procedural query language. It consists of a set of Bo that tole one or two operations &s input and produce a new relation ss result definition of the relational algebra : ‘A basic expression in the relational algebra consists of either one of the following = = Arelation in the database = A constant relation A constant relation is written: by listing its taples within {for example {A - 101 Downtown, 500) (A-215, mianus, 700) }- expression in relational algebra is constructed out of smaller sub Ter end &; be zelational algebra expressions. Then, following all are algebra expression * hub 5 -E E,xE2 cp (Eu) where vis 2 predicate on attributes ink «(Ej)» where § isa ist consisting of some of the attributes iy 5. pe (Er) where 2 is the new name for the result of F elational algebraic operations are divided into two groups 4) The first group includes the set operstians Sines each relation is defined as 2 set of tuples, thy set operations ere applicable to the selotional data model. Set operations include the following operations = Union © Intersection + Set sifference = Cartestan product ii) The second group of relational algebraic operations 1 developed specially for qelational databases. Some of the operations of this group are = Select = Project Database Management Systems 2.5.1 Fundamental Operations in Relational Algebra 25.11 Union, Intersection and Difference Union, intersect union compatible. Two relations are said to be union compatible if the conditions are satisficd + a © The two selations/tables must contain the same number of columns the same degree). Each column of the first selation/table must be either the same data typ the corresponding column of the second relation/table or convertible to: same data type as corresponding column of the second. Consider following two relations = Depositor T Custemer_name City Vans Pine wonnsan umba ones ‘Solapur Lindsay Nashik ‘math Pane Turner Willan Kathie Fig. 24 A Depositor and Borrower relation ‘Management Systems 2-13 Relational Model 4wo relatiens are union compatible. Now we will see four set oriented PMay-03, 2 Marks] ‘The result of operation is denoted by Depusitor \ Borrower, is the relation that all tuples that are either in Depositor or Borrower or in both. Duplicates are ted. Fig. 2.5 Result of union operation 2) Intersection IMay-03, 2 Marks] ‘The result of intersection operation is a relation that includes all tuples that are in ‘both Depasitor and Borrower. The intersection operation is denoted by ‘Dopositor+Berrower. Example : Find the names of customers who have both an account and loan, The result of intersection is = Fig. 2.6 Result of intersection operation Database Managoment Systems 3) Difference The difference operation js denoted by Depesitor - Borscaver ‘The result difference operator is the relation that contains all tuples in Depositer but Bocrower. Rachie Mumbai =| Fig. 2.7 Result of difference operation Both union and intersection operations are commutative and associative o; ‘This means that following are true : + AUB= BUA ant ANB=BNA * AVEVO) = (AUB)UG ad AA(BNC)=(AnB)AC ‘The difference operation is not commutative. This means that A — B is same as B—A or in other words A-BeB~A 4) Cartesian Product [Meoy-05, 2 The cartesian product is also known as CROSS PRODUCT or CROSS JOINS. denoted by x’. The cartesian product of two relations A and B is denoted by Ac The result of cartesian product of two relations which have X and Y columns relation that has X + Y columns. The resulting relation will have one tuple or combination of tuples from each participating relation, Hence if the relations and m tuples respectively, then the CARTESIAN PRODUCT will have n * n. tap! Consider following two relations ; Publisher Info and Hook Info. Fig. 2.8 Publisher_tnfo and Book_Info relation Relational Mode! “The selation Publisher_Info has 2 columns and 3 tuples. The relation Book Info has columns and 2 tuples. So the cartesian product has 4 columns (242) and 6 tuples (G2) The cartesian product of Publisher_Info and Book Info is given in Fig, 29: Publisher_Info x Book info Name Book 1D ood Fig, 29 Gertecian product of relations Publisher_Info an Book_info 4.2 The Select Operation [Mey-03, 2 Marks} +The select operation selects tuples that satisfy a piven predicate, ‘s The select operation is represented as follows : Gazeiat enstcn> (R) “< attribute mame > < consparison. operator > < constant vali > te << atiriiute name > < cotsparison operator > < alirimute name > where, ‘s < ottriude name > is the name of an attxibute (column) of the relation R. =< comparison aperstor > is one of the following comparison operators 5.2% «constant value > 6 the constant value (rom the alfibuie domsin Clauses are connected by boolean operators AND, OR ‘and NOT to form general selection condition. Database Management Systems 2-16 Consider following Book relation as shawn in Fig, 2.10. Book fd) Tits | Author > Examples Following are the some examples of the select operation, 1) Display books published i yer 2000, = rece = a0 (Book) The output of above query is shown below : Book id| Tile | Author | Publisher poor | news | corm | notre - Hit pos | ret | Santa 2) Display all books having price greater thn 300, = Spon = spn(Book) The output of the above query is shown below Book | Title | Auther | Publicher 89002 | Compiler |_Ulnan Boos | COND | Ramtough soot | ppt | Sabista 2500 3) Select the tuples for all books whose publishing year is 2000 or price i greater 300 2 Gitom — m000) tien = ey BOCK) ‘Database Management Systems 27 “The output of the above query is shown below : Book f4| Tite | Author | Publisher Price ‘aco orth | McGraw - Hl 250 350 120003 Rambaugh 450 0008 Salata ~ | 2000 | 500 8) Select the tuples for all books whase publishing year is 2000 300. 2 Sirens = amo) ana Pn > oop (BOC) “The output of above query is shown below = 254.3 The Project Operation [Proy-03, 2 Marks) “The project operation selects eertain columns from a table while discarding others Icremoves any duplicate tuples from the result relation. ‘The project operation is represented as follows Th axis (RD) ‘The symbol 11 (pi) is used 10 denote the project operation and the attribute list a list of atiributes from the attributes of the relation R The result of the project operation has only the attributes specified in the attribute Hist and in the same order as they appear in the list. Hence the degree (number of columns) of the result is equal to the number of attributes specified in the attabuie list ta > Examples = ‘The following are the examples of project operation on Book relation, 1) Display all tilles with author name. = Une acinar (Book) ‘ Database Managemont Systems: 2-18 Relational ‘The outpat of above query is given in Fig. 211. Title Author ams Koa Compiler comp PPL Sabet Fig. 2.11 Title and Author of Book 2) Display all book titles with authors aid price. o> Th pide, Author, tien (Book) ‘The output of above query is given in Fig. 2.12 Author Kerh Salvia {Reset ei meee Fig. 2.12 Title, Author and Price of Books 25:4 Composition of Select and Project Operations ‘The relational operations select and project can be combined to form a complica query. Example = 1) Display the titles of books having price greater than 300. => Thin (Genco > s00 (B00l)) ‘The output of the above query is given Fig. 2.13 Title of the Books: ‘Detabaso Management Systems Rolational Medel 254.5 The Rename Operation [P8e-02, Mey-03, 2 Mer] In relational algebra, vou can rename either the relation or the attributes or both. ‘The general rename operation can take any of the following forms : F) Deg (ew attibate narrent (RE) ides (RB ‘ii) B irew aeribate names) (R) ‘The symbol ‘p' (rho) is used to denote the RENAME operator. “S’ is the new ‘elation and ‘R’ és original relation. ‘The first expression renames both the relation and its attributes, the second senames the relation onlly and the third renames only the attributes. 5 > Examples = For example consider the Book relation with attributes Title, Author, Year and Trice. The rename operator is used on Book relation as follows : 1) P Teepe, Annme, Pyeac tyre} (BOOK) Here both the zelation name and the attribute names are renamed. 2) P Tom (Book) Heze only the relation name is renamed. 9) 9 em sme Pow Rp (BOOK) In this case, only the attribute names are renamed. 25.2 Additional Operations in Relational Algebra The fundamental operations in relational algebra are select, project, union, set

You might also like