0% found this document useful (0 votes)
7 views

DBMS2

The document provides an overview of the relational model in database management systems, covering topics such as relational algebra, relational calculus, SQL queries, triggers, and integrity constraints. It explains the differences between procedural and non-procedural query languages, and discusses various types of integrity constraints and key constraints. Additionally, it includes short questions and answers related to the relational model, views, and the enforcement of integrity constraints.

Uploaded by

shinchanm1809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
7 views

DBMS2

The document provides an overview of the relational model in database management systems, covering topics such as relational algebra, relational calculus, SQL queries, triggers, and integrity constraints. It explains the differences between procedural and non-procedural query languages, and discusses various types of integrity constraints and key constraints. Additionally, it includes short questions and answers related to the relational model, views, and the enforcement of integrity constraints.

Uploaded by

shinchanm1809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 16
© Database Management Systes UNIT INTRODUCTION TO RELATIONAL MODEL Relational Algebra and Calculus : » Preliminaries, Relational Algebra, + Relational Calculus +s Tuple relational calculus 4 Domain relational calculus _. Expressive power of Algebra and calculus SQL: + Queries + Constraints = Triggers = Form of basic SQL Query, + UNION, INTERSECT and EXCEPT, nested queries. — Aggregate operators = NULL values complex integrity constraints in SQL —+ Triggers and Active Databases + Designing Active Databases Relational Algebra: + Relational Algebra is a query language which is used to manipulate the data in the relational data model. Relational Calculus: + Relational calculus is an example of non-procedural languages. Non- procedural language allows the users to specify what data is required rather than how to get data. Queries: > A query is a request for data or information from a database table or combination of tables. Triggers: > A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. \Marning : Xerox/Photocopying ‘of this book is a CRIMINAL Act. Anyone found guilty is LIABLE to face LEGAL proceedings Database Management Systems i Short Questions with Answer, What is relational model? Give a examples ? Qu. store the data ina Relational model is one of the database model that uses tables to sim, le tabl May Implicity is due to the usage of tables in which an entity is represented as a table relation ane’ instance by the rows of the table (tuples) Example: Its si A student entity is represented as a table whereas an individual student corresp, Tows in the table. A relation ina relational model consists of (i) Arelation Scheme (i.e. heading of the column) (ii) A relation instance (ie., table) Q2. What isa view? Ans: ond to, Views are derived or virtual tables, they does not exists and derive their data from the Origin relation views allous the user to see only the part of the data but not all data. ae user can think, view as any other normal relation and can perform all the operations that can be pe formed on relat Views are dynamic in nature. i..e, the changes / modifications made to the views are reflected bacy ty the original table and vice versa Q3._ ER diagram for weak entity set ? Ans Consider an ER diagram representing information of Rugby team. _ 3 Rugby Team Here the entities of the entity set “Players” (i.e., name, number and role) cannot be identified 2s other teams may also have a player with same hame, number and “Player” is a weak entity set. This is b included with one or more “Many ~ one relationship” anda key of the r entity set. Q4. What are integrity constraints? Ans: a) As soon as the database scheme is def b) Validity of the changes made to the di Q5. Write a short note on Relational Alge Ans : Relational Algebra is a procedural query lan j ; wage whi , pata vields instances of relations as output. Ituses creme reich aes instances of relations as inne unary or binary. They accept relations as their input and yietg ‘orm queries. An operator can oe ceo" isperformed recursively ona elation andintensegen result tS 8s their output relational Warning XerodPhotocopying ois books a CRRA Teyona ae Sito considered relations ot Suit is LIABLE to face LEGAL ge 06 Relational Calculus ? 1 Calculus is a non procedural query Beasts! mathematical predicate calcults Ff algebra. Relational calculus is an » relational algebra, In contrast to the a eh is procedural, the calculus in non J ay declarative, in that it allows us to sho set of consures without being explicit vei pew should be computed. Relational vo Chas a big influence on the design of vm) query languages such as SQL, the vehe calculus we present in detail is called jonal calculus (TRC). d projection Relational “yapie relat What is selection relational algebra ? nal algebra includes operations to irom a relation («) and to project These operations allow us to ate in a single relation the symbol for peration is 0. This operatin is used to ‘ar rows from the two relations which given condition. This operator is used to display the list of utes columns defined in the relation R Syntax tablename) attributes) (tablename) (columns) Define set operations of relational algebra? s: _ The following standard operations on sets Be aso available in relational algebra: Union(U), tersection (n), set difference (-), and cross ~ Product (*) (a) Union (U) : Mie applied on two relations, it returns all rows which are either. present in first relation or second relation oF in both relations. It does not return the tows which 'as the same.tuple values, representing rows. °Q10.Define joins in relational Algebra ? Inte When applied on two relations A and B, it (A 1 B) returns all the rows which are common to both the relations, Most importantly this operator can be applied to only those relations that are union compatible Set difference (Minus ‘-’) : This operator is called as “Minus” operator. If A and B are two relations and are union compatible than (A-B) with return all the rows which are in A but not in B (c) Cros-product (*) : This operator returns all the tuples of relation A plus all the tuples of relation B corss product is denoted as AXB returns the Cartesian product of two relations the relati (a) Q9. Define rem * Algebra? Ans: This operator is used to rename the relation or attributes or both Syntax : P(A (oldname > new name),B) Bis the old relation which being renamed as ‘A’, the list which contains the new names of attributes is called as remaining. For example the relation DEPT_LACATION to DLOCATION and the attributes DNO TO D- number and DLocation to D_La an be remaned in the following manner. P(DLOCATION (DNo> D_number, D Location —> D_L) DEPT_LOCATION) Ans: Joins are used to combine the informationa of two relations which have atlease one filed in column. It is one the most important operator of RDBMS. In simple words, a join operator can be defined as a cartesian product followed by selection or projection operators. The different forms of join operator are (a) Conditional join (Meta join q) (b) Equi - Join (c)__ Natural Join (d) Outer join "ng : Xerox/Photocopying of this book Is a CRIMINAL Act. Anyone found guilty is LIABLE to face LEGAL proceedings ‘a & be Consider two relations P and Q such that P contains two attributes ‘a’ & Qontains ony, attribute ‘b’, The attribute 'b’ in or has similar domain as that of p. Thus a win Opera represented as P/Q can be defined as the set of all values of ‘a’ where in each volume of b’ in Q ‘a’ tuple in P f . Assume that for a set ‘b’ values in p there exits a corresponding set of ‘a ve lues in ‘p’ L| the value ‘a’ is said fo occur in the result of P/Q if the set of values of *b’ in P has all the values oj inQ Q12.Explain the types of relational calculus ? Ans: The two types of relational calculus are (1) Tuple caleulus and (2) Domain calculus ~ (1) Tuple relational calculus (TRC) : TRC mainly deals with the tuple variable for which the predicate is evaluated. A tuple varia. a variable which takes a'tuple as it is values. A TRC query can be represented as, {A/PIA)} where, denotes a tuple, variable and P(A) is in a predicate that gives the description of A. (2) Domain relational calculus (DRC) : DRC is similar to TRC but the only difference is DRC make use of domain variable instead tuple variable. Domain variables are those variables which are defined for the domain value of atribu.. The general form of DRC query is ((al,a2,23........an)/F((al,a2,a3,......ani)} Q13 Discuss the difference between the relational algebra and relational calculus ? Ans: Q11. Define division in relational Algebra ? Ans: Relational Algebra Relational Calculus 1. Itisa procedural query language | 1. Itisanon procedural query language 2. We specify the sequence of operations 2. We specify the only what is required to perform a particular request. | without bothering about the sequence : : of operations to perform that requests 3. Relational algebra is not domain 3. Relation calculus can be domain dependent. dependent. 4. Its close toa programming language. | 4. Itis close to the natural language | 5. It is describes the order in which 5. It does not specify the order of | operations have to be-performed, | operation | 6 his easytolearn, | 6 Itisdiffcutt to learn Q14. List Various Types of Integrity Constraints? — (a) Domain Integrity (b) Entity Integrity (c}_Referential Integrity (d)__ Key Constraints Q15. List of different types of Key Constraints ? Ans: (a) Candidate key (b) Super key (c)_ Primary key (d) Foreign key Warning: Xerox/Photocopying ofthis book isa CRIMINAL Act. Anyone found guiy & LIABLE we face LEGAL proce? | Database Management Systems Essay Questions with Answers Referential integrity - constraint : 99.1 INTEGRITY Constraints Over 3 RELATIONS It states that if a foreign key exists in a Write a brief note on history of Database | ‘elation then ‘vithor the foreign key value must match a primary key value of some tuple in its system ? home relation or the foreign key value must be null ns: tea The rules are : | (1) You can't delete a record form a primary .q record exists in a related rity Constraints: Intearity constrains ensure that changes ade to the database by authorized users do not erin a loss of data consistency. This Integrity quard against accidental damage to the | (2) You can't change a primary key value in the primary table if that record has related records, table of matchin | table ponstrains taba: ample of Integrity constraints are: An instructors name cannot be null (3) You can’t enter a value in the foreign key «two instructors can have the same field of the related table that doesn't exist in the primary key of the primary table. 1D Gepartment name in the course relation (4) Key constraint: A key constraint is a have a matching department name in statement that a certain minimal subset of tle department relation. the fields of a relation is a unique identified | for Auple. .dget of a department must be greater 0.00 ypes of Integrity constrain: of integrity constraints are Domain integrity Entity integrity constraint There are 4 types of key constraints (1) Candidate key | (2) Super key (3) Primary key (4) Foreign key 2.2 ENFORCING INTEGRITY CONSTRIAINTS Q2. Explain in detail about enforcing intes- constraints ? Relerential Integrity constrains Key constraints Domain integrity : Domain integrity means the definition of a Ie er of values for an attributes. You define | AMS * ‘a tupe, Ienaths of size, is null values, default | Enforcing Integrity Constraints : jlue. the range and/or specific values for the e Integrity constraints are the rules are the rules « that when applied on relations restricts the insertion of incorrect data. They also help to prevent deletion and updation of consistent data that may lead to loss of data nibutes Entity integrity constraints : This rule states that in any database relation alue of attribute of a primary key can’t be null. Example - Consider a relation “STUDENT” integrity. hhen ‘stu_id’ is a primary key and it must not contain any null value eg ‘Branch’ inthe following © The operations such as insertion, deletion F icneontsinscnetnull value and updation must be discarded if they are found to violate integrity constraints. © This section provides a brief knowledge on Stu_id 7 (25234 4 different violations of IC's and also the [iass969 _ — solutions to handle these violations, {11258324 Example : 11058678 Aastha | | © Consider the instance S, of students from =. - following figure ‘Warring: KeroxiPhotocopying of ths Book ls a CRIMINAL Act. Anyone found gulty is LIABLE to face LEGAL proceedings base Management Systems @ . - oh FIELDS (ATTRIBUTES, COLUMNS) Ae, cae eS No & —— sid | name login [age [gpa] a 50000 | Dave dave@es 19 | u 53666 | Jones jones@es 18 P +3688 | Smith smith@cc 18 L 53650 | Smith | smith@math 19 e + 53831 |Madayan| madayan@music | 11 y 53832 | Guktu | Guldu@music | 12 _ The following Insertion violates the primary key constraint because there is already a tuple witp Sid 53688 and it will be rejected by DBMS. INSERT INTO Students (Sid, name, login, age, gpa) VALUES (53688, ‘Mike’, ‘mike@ee’, 17, > The following insertion violates the constraint that the primary key cannot contain null ; Insert : Into students (Sid, name, login, age, gpa) VALUES (null, ‘Mike’, ‘mike@ec, 17, 3.4) However, an update can cause violations ‘ UPDATE students S SET —S.sid = 50000 WHERE S.sid = 53688 This update violates primary key constraint because there is already a tuple with Sid 50000 The following insertion is illegal because there is no students tuple with Sid 51111 : INSERT INTO Enrolled (Cid, grade, studid) VALUES (‘Hindi101', ‘B', 51111) SQL allows us to choose any of four options on DELETE and UPDATE CREATE TABLE Enrolled (studid CHAR (20), cid CHAR (20), grade CHAR(10), PRIMARY KEY (studid, cid), FOREIGN KEY (studid) REFERENCES students oN DELETE CASCADE ON UPDATE NO ACTION) 2.3, Queryinc RELATIONAL MODEL Q3. What is relational database query ? Explain briefly. Querying Relational Data : Query is a question. A query is formulated for a relation/table to retrieve same useful information from table. Different query language are used to frame queries Example : Consider the instance of students relation from following FIELDS (ATTRIBUTES, COLUMNS) sid] name bog [age [gpa] eaveoes 33 "i jones@es [34 | ¥ 32 | t Lb sie b 38 © 1 seat madayan@music | {53632 Guldu@music | 12) 20 , ig ESS UE BOSE RMA A Pops Tn GY ULE FE od @ Database Management Systems «can wettive rows corresponding f students who are younger than 18 with following query SELECT * FROM students S WHERE Siage < 18 cjudonts with age < 180n Instance , is ee iW a 12 | 20 sn addition to selecting a subset of tuples, a query ca sclected tuple We can compute the names and logins of students sid a8 [Madayan] madayan@music | Reaaz | Golda | Guku@muric n extract a subset of the fileds of each who are younger the 18 with following query SELECT Sname, —S.login FROM Students Ss WHERE S.age <18 SELECT S.name, E.cid FROM Students S, Enrolled E WHERE S.sid = E.studid AND E.grade = 4 Locicat DATABASE Desicn _ Explain logical database design indetail ? \s he process of logical design involves arranging data into a series of logical relationships called sigs and attributes. nverting Entity relation diagram to relations/Tables. ‘Any entity - relations (ER) diagram can be converted to relatic « of attributes entities relationships which taken altogether descrit caches discussed below on ER diagram it can be converted to a set o nts a relation and attributes of entities represents the columns of the relation. Transforming entities to relation : The entities present in an ER diagram correspo! corresponds to the attributes of relation for examnp! name as course_id, $_id, Class_id, Grade. ‘onsitables. A logical database bes a database. Based on the f tables where each entity nds to the relation and attributes of the entities le consider the student ER diagram with attributes Name at) ‘This ER diagram is translated into relation “Student” as shown below. Warring: ing: KeroxPhotocopying of this book is a CRIMINAL Act. Anyone found guilty is LIABLE to face LEGAL proceedings Database Management Systems @ » Name [6 id Class id | Course id | Grade Ny ‘Sirisha [20 [86 [43 B Vani 155 [83 | 21 A Anuradha | 05 | 86 | 43 Archana | 22 | 84 26 Swathi | 51 | 83 21 SQL statement for the creation of table CREATE TABLE Student (Name (CHAR(30), S_id INTEGER, Clas_id INTEGER, Course_Id INTEGER Grade CHAR (1), Primary KEY (S_id) Transforming relationship sets to table (Without constraints) : : lations. These attributes of this relatio, Relationship sets are converted / translated into re se attri is on, of primary eve al other entities which ae related (0 this relationship and aso its own ati, Consider the following ER diagram Gee) : ‘Name “I Lacaer Gros. Cotege / co | Gm) Sine >) Phone number <>) ER diagram representing relation between lectures and college This ER diagram can be converted into three relations namely, lectures, college and works in wit following attributes. ‘Lecturers (Lecturer_id, course_id, Dept, Name) College (college_id, Name, Phone_number, Address, No_of_dept) Works-in(lectures_id, college id, since) The following are SQL statements for creation of telation_works_in © Al the attributes of works_in_relation taken together from superkey. © —_ Underlines attributes of works in relation the set of candidate key. CREATE TABLE WORKS in(lectures_id INTEGER, College_Id, INTEGER Since DATE, PRIMARY KEY (Lectures id, College id) FOREIGN KEY (Lecturer_id) REFERENCES lectures FOREIGN KEY (college_id) REFERENCES college); Work in Lecturer id | College id | Since 7 ul 10-8 ~ 1985 72 13 25-4 2000 23 14 124-1989 74 15 01-01 - 2006 ring KooxPhotoSops a book sa CRNA Aa Py Tound pay UABLE sce LEGHL oO 398 15 [yrRODUCTION TO Views 5 2 pat is a view? Explain br telly ? a5: Ans views: Awiew iS jatabase. T ‘away of portraying information in yyis can be done by arranging the ya specific order, by highlight certain vay database, there are number of that may be specified, Database with vee gen to have more possible views than mor Hh fee ies offen thought of a8 aaiabaettple. the view doesn't actually store oon itself, but jack pulls it out of one or saisting table on of views. following SQL statements are used to create a view. CREATE VIEW (view, name) (fieldl, field2, fieldn) ELECT (attributes!, attributes2,, ined cinta item toms ten Creat The FROM tablel, table2, seoeetablen WHERE ‘Tiss the general format for defying a view. Exemple : Let us suppose, we want to create a view fcr employee table. This view gives the information about the ++ located as New jersey. 7 CREATE VIEW project_info (Name, Id, DNo, Poumber, Prame) As SELECT E.Ename, E.Eid, E.DNo, PDNO PPName FROM employee E, PROJECT P WHERE E.Eid=PEid. AND PLocation = New Jersy’ 7 The view project_info contains the following ie Name (of employee who are working on project], Id, DNO, PNO, PName) i@ | Name [ DNo | Phumber 12345263 | Green [7 | 51 12345262 | Jack | 7 ln 2.6 Destrovinc/ALTERING TABLES & VIEWS 6. Discuss about destr r jt kecagn about destroy ing / altering of ‘Ans : Destroying table - Destroying or deleting a table crag can be done with the help of DROP @ Database Management Systems Syntax : DROP TABLE table name RESTRIC T CASCADE The keywords RESTRICT/CASCADE must always be used with DROP command Destroying views : ‘A view can also be deleted with the help of DROP command Syntax : DROP VIEW view name Exampl Drop view project_info Altering table ALTER TABLE command is used to modify the structure of the table ALTER TABLE tablename ‘ADD[COLUMN] column name datatype DROP[COLUMN] columnname RESTRUCT/ CASCADE ADD[CONSTRAINT] Constraint name DROP[CONSTRAINT] Constraint name RESTRICT/CASCADE [ALTER[COLUMN] SET DEFAULT default option) [ALTER[COLUMN] DROP DEFAULT} With Alter command following modification can be done (a) Addition of column (b) Deletion of column (c). Addition of constraint (d) Deletion of constraint (e) Setting a default value for a column Example : @ ALTER, TABLE employee @ ADD Project_number INTEGER SQL constract for modifying structures if views Syntax : ALTER VIEW viewname ALTER[COLOUMN]columnanem SET DEFAULT Default option. Example: ALTER VIEW Project_info ALTER[COLUMN] project name SET DEFAULT “Online enrollment” Waring = Xerox/Photocopying of this book is a CRIMINAL Act. Anyone found guilty is LIABLE to face LEGAL proceedings Database Management Systems ky 2.7 RELATIONAL ALGEBRA > Q7. What is relational algebra? List the operations of relational algebra? Explain operation in detail of relational algebra ? Ih Ans Relational Algebra : Relational algebra is a procedural query language which takes reas of pater aS in, yields instances of relations as output, An operators can be either unary or binary. They accep, Teles as their output. The fundamental operations of relational algebra are as follows © Select Project Set operation Rename Joins Divisions SELECT operation (<) : It selects the tuples that satisfy the given predicate from a relation. Notation ( Where ostands for selection predicate and r stands for relation P is proportional logic form, which may use connectors like and, or and not these terms may use relational operators like - = <2 For example : (1) 6,24 = “database” (Books) Output : select tuples .from books where subject is ‘database’ (2) O,.4.= “database” and price="450" (Books) Output : Select tuples from books where subject is ‘database’ and ‘price’ is 450 (3) seq = “database” and price ="450" or year Output : Select tuples from books where subject is ‘database’ and ‘price is 450 or those boc: published after 2010 Syntax : Syntax for selection operation is contain tablename. Q8. (a) Explain project operation? (b) Explain rename operator ? Ans : (a) Project Operator : This operator is used to display the list of attributes / coloumns defined in the relation R Syntax : Tonge: tablename or Tcsuunm tablename a Warning ? KeroxiPhotocopying of this book is a CRIMINAL Act. Anyone found guilty le LIABLE to face LEGAL proceeo™™ gue ample : pisplay proie’ w only these co! {NO. DNO from relation PROJECT p,.. aa Joumns are selected and displayed whi @ Database Management Systems DNO (PROJECT) le other colournns are eliminated from spe ton eo: eee tid Fuiowe | Akess | Sex | Salary | DNO | PNo | Age ohn | 12345261 | 10:8:1965 | New jersey | M | ano | 7 | 779213218 | 41 | eek. | 12345262 | 12.6-1955 | Chicago | M | 58000) 7 719421317 | 51 en 12345268 | 20-11-1972 ] New York | M | 20000) 7 TISAUBIT | 34 Brown, 12345264 | 28-7-1968 Chigo M 40000) 8 7134210192 | 38 Ta | 12845265 | 254.1955 | Detro | F | 35000) 8 7732718420 | 51 iy 12345266 | 4-4-1905 | New York | F | 42000) 8 773291828 41 anak 12345267 | 281968 | Detroit | M_ | 20000 9 | 773223145 | 28 an 12345261 | 108-1965. | Newjersey | M | 25000) 8 773213218 | 41 ishn 12845261 | 10:8:1965 | New jersey | M_| 25000] 9 eee peraRTMENT : DEPT_LOCATION ee Dname DNO | Manager id DNO_|__DLOCATION | Administration 7 7 New York Research 8 8 Detroit Headquarters | 9 ae Chicago _ pROJECT: Eid | PNnumber | _ PName | PLocation | DNo | 12345261 | 21 | Computerization | New York | 7 12345265 | 31 Product | Detroit | 8 | 12345267| | 41 New Benefits | Chicago | 9 | | 12345263 | 51 Soft Drinks | New Jersey | 7 | 12345264} 61 | Reorganization | Chicago | 8 | 12345263 | 71 Product | NewJersey | 7 Dependent : Eid | Dep_Name | Sex | Relationship 12354261 | Nivedita | F | Mother 12354262| Alan | M | Brother | 12354263 | Lit | F | Sister | 12354261 | Roven. | F | Daughter | 12354265] Peter | M | Father 12354266 | Kumar | M | Brother 12354267 | Sunny | M | Son Projection : 7 [__ PNumber DNO 21 7 31 8 41 9 51 7 61 8 ‘ | Database Management Systems se, suay (EMPLOYEE) This query will display the colours of sex and salary from EMPLOYEE. Projection : SEX I SALARY _| | iM | 25000 35000 20000 40000 35000 | | 4200 mnZZzZZ The difference between select and project operator is that former operator satisfies commyray.._ property Example: ifthe user wants to display the emp_id, emp_name, birthdate, salary of the employees whose 2», is greater than 30, then the expression can be represented as ' “Eid Eid. ename,Bdate.Salary,Age(o Ag>30 (EMPLOYEE) This will return the following relation PROJECTION : [ i [Ename | Bdate | $Salary| Age (years) | | 5 12345261 | John | 10-8-1965 | 25000 | 41 12345262) Jack | 12-5-1955 | 55000 SI | | 12345263 | Green | 20-11-1972) 20000 34 | 12385265 | Bil | 25-4.1955 | 35000 | 51 | {12345266 | Jill | 044.1965 | 42000 41 Q9. What is relational algebra ? Explain set operations in detail ? Ans: Relational Algebra Refer essay question 7 for relational algebra Set operations : The following standard operations on sets are also available in relational algebra: union (u): intersection (n), set - difference (-) and cross-product (*) (i) Union: RUS returns @ relation instance containing all tuples that occur in either relation instance R of relation, instance S (or both). R and S must be union-compatible, and the schema of the result is defined to identical to the schema of R Two relation instances are said to be union-compatible ifthe following conditions hold. > The same number if fields and > Corresponding fields, taken in order from left to right, have the same domain ii) Intersection : | RAS returns a relation instance containing all tuples that occur in both R & S, The relations R & Warning: XeroxPhotocopying ofthis book sa CRIMINAL Act. Anyone ound guy s IABLE to face LEGAL proceeding? oe ‘a be union compatible, and the schema of Hels defined to be identical to the schema Set- Difference Jp Syeturns a relation instance containing all ccuy in R but not in’. The relations R «be union compatible, and schema of < defined to be identical to the schema of sth ul Crose-Prodect gv Syeturns a relation instance whose S The result of RX § contains one ach pair of tuples rER, SES. The peration is sometimes called Give the examples for set operations Sd | Bid | Day _| 2 | 101 | 10/10/96 | 58 103 11/12/96 | ¢ sion of S1 and $2 is shown in Figure © listed in order: field names are also on 51. S2 has the same field names of it is also an instance of sailors. In ds of S2 may have different names, 4! appear in both $1 and $2 appear only n SIVS2 Sid | Sname | Rating | Age 2° Dustin) 7 | 45.0 | 31 | Lubber| 8 | 55.5 | 58 Rusty | 10. | 35.0, 9 |350 5 [50 Fig 1.1 ~ S182 nine all the fields of R followed by all | @ Database Management Systems The result of the cross product SI * RI is shown in Fiqure 14 because RI and SI both have field named sid, hy our convection on field names the corresponding two fields in SI * RI are unnamed and referred to solely by the position in which they appear in Fig 14 the field in $1» RI have the eame domaine as the corresponding fields in RL and SI. In fig 1 4.sid is listed in paratheses to emphasize that it is not an inherited fields name only the corresponding domain is inherited [Sid | Sname | Rating | Age | 31 | Lubber| 8 =| 555 [58 | Rusty 10 | 350 Fig 1.2 - $1082 Age | Sid | “|_| 22 | Dustin | 7 {= Fig 1.3-$1- $2 [Sid [ Sname | Rating | Age (sid) | (bid) | Day 2 | Dustin | 7 | 450) 22 | 101 | 101096 22 | Dusin | 7 | 45.0) 58 | 108 | 111296 31 | Lubber| 8 | 55.5| 22 101 | 101096 | 31 |Labber) 8 | 555 58 | 103 | 111296 | 8 | Rusty | 10 | 35.0 22 | 101 | 10/1096 | 58 | Rusty | 10 | 35.0 58 | 103 | 111296 Fig 14-S1*Rt QUI. What are joins ? Explain in about joins ? Ans: Joins are used to combine the information of two relations which have at least one field in common. It is one of the most important operator of RDBMS. In simple words, a join operation can be defined as a Cartesian product followed by relation or projection operators. The different forms ‘of join operators are (a) Conditional Join {b) Equi - join (c)_ Natural join (d) Outer join (a) Condition Join : The most general version of the join operation accepts a join conditions C and a pair Management Systems @ of relation instance as arguments and returns a relation instance. The join condition is identical to selection condition in form. The operation is defined as follows ReS = 5, (RX §) Thus © is defined to be a cross product followed by a selection Example: The result of Sleis shown in the below figure. Because sid appears in both SI and RI, the corresponding fields in the result of the cross product SIX RI (& therefore in the reslt of Slo... gaa) are unnamed domains, are interfered from the corresponding fields of S1 and RI Sname Rating | Age | (si) | Bid _ Day | 7) a5) 58 | 103] 11/1296 Dustin | 0 Lubber 8 | 5558 | 103 | 11/12/96 (b) Equi - join: A. common special case of the join operation R x Sis when the join condition consists of solely ‘of equalities of the form R.namel = s.name2, that 's equalities between two fields in R and S. In this case. obviously there is some redundancy in retaining both attributes in the result for join conditions that contain only such equalities, the join operation is refined by doing an additional projection in which s.name2 is dropped. The join operation with this refinement is called equijoin . Slog,4s.RlIn figure note that only one field is called sid appears in the result. Sid | Sname | Rating | Age | Bid-| Day 22 | Dustin 7 | 45 | 101 | 10/1096 58 | Rusty | 10 | 35 | 103 | 11/12/96 | Fig: Ste pugsadRt (c) Natural Join : This is default join operation i.e, no condition is specified natural join is equivalent to Cartesian product. If two relations have a common field then the application of natural join is equivalent to equi join and if no field is common then the natural join is Cartesian product of the two relations. This operation can be denoted as, AB where a and B are two relations (d) Outer joins : Some intersecting variants of the join YA are supported in SQL consider the join of say sailors Wc, eserves tuples of Sailors not match some row in reserves according te join condition c do not appear inthe resyp There are several variants of the ou, Ina left outer join, sailor rows without a myst % reserves row appear in the result but not vice In a right outer join, reserves rows wig matching sailors row appear in the resul, He outer join both sailors and reserves rows yi, match appear in the result ny, 2.8 Tupte RELATIONAL Catcutus, Q12. What relational calculus? Expta in about relational calculus?” Ans: Relational calculus is a non-procedura|, language. It uses mathematical predicate cj." instead of algebra . it provides the descrips,,.. about the query to get the result where as r\,.,.” algebra gives the method to get the result, There are two types of relational calculus They are (1) Tuple relational calculus (TRC) (2) Domain relational calculus (DRC) (1) Tuple relational calculus : A tuple relational calculus is a ao, procedural query language which specified to sie- the tuples in a relation. It can select the tunis with range of values or tuples for certain attribu': values. {t/p(t)} or {t/condition(t)} Where it is the resulting tuples, p(t) sth condition used to fetch it. (2) Domain relational calculus : In constrast to tuple relational calculi domain relational calculus uses list of attribute the selected from the relation based on conditie: It is same as TRC, but differs by selection attributes rather them selecting whole tuples. Itis denoted as below (sayy ayy ayy. a,>/P (As Ay A a} Where a,,a,,a,.....a, are the attributes? the relation and p is the condition operation that rely on null values called outer joins Warning : Xerox/Photocopying ofthis book is a CRIMIN - Anyone found guilt is LIABLE to face LEGAL 0° @ Database Management Systems and Relational Calculus 158 13. Discut Itis a procedural query language nces between the Relational Al; 1. Itisanon procedural query language. 2. Operations are directly performed on the It specifies operations performed on relations in form of formulas. existing relations to obtain new relations. Itis more closely associated with query 3. Its more closely associated with a Janguage. natural language. ‘These queries are domain independent 4, These queries are domain dependent. 5. _Itallows the programmer to specify what data is required but not the way of retrieving it. Itallows the programmer to specify what data is to required also the way of retrieving it 6. _Itis possible to express all relational It is retricted to safe queries on the algebra queries into relational calculus. calculus + This mostly preferred by the programmers. It is inferior than relational calculus. 6 7. It is mostly preferred by the end users. 8. Itis superior than relational algebra. «> Itisnotconsideras user-friendly language. | 9. _Itis considered a user-friendly language The level of abstraction is low. 10. The level of abstraction is high. The implementation of relational algebra 11. The implementation of relational calculus} 11. is more efficient. is less efficient. 12. It determines the order of evaluation 12. It determiners the order of evaluation based on the compiler or interpreter. by itself. 13. It is easy to learn. 13. _ It is difficult to learn. 14. The quaries are represented in a logical 14, The queries are represented in an algebraic form. form. It defines a relation in termsof one or 15. It defines a process of building arelation | 15. more relations. from one or more relations. 14. Relational algebra and relational calculus are said to be equivalent in expressive power? Discuss? Expressive power of Algebra and calculus : Both the languages relational algebra and relational Jculus are logically equivalent that is all the queries which can be expressed in relational algebra can expressed in relational calculus. But the reverse may not be true. For example consider a query {E|=(E< EMPLOYEE) } This query will result in the set of emy MPLOYEE. ‘Any calculus formula is said to safe if it is one of the following. The resulting set R contains the values which are in the domain ‘of Qand S where Q is query and Sis a set of relational instances 7 R — domain (Q,S) For any S.R should consists of the values present in domain (Q,S) The sub formula 3 x (P(x))is true of any value ‘a’ then this value ‘a’ contains only constants present in the domain. The sub formula V x (P(x))is true for a value ‘a’, then the value ‘a’ contains constants that is not present in the domains. However these definition are not enough to check whether a given query is safe or not. ployee E such that E does not belong to the relation. Warning 7 “ering : Xerox/Photocopying of this book is a CRIMINAL Act. Anyone found guilty Is LIABLE to face LEGAL proceedings 29 Doman Rewamionat CatcuLus Q15. Explain briefly Domain Relational Calculus ? Ans: Domain Relational Calculus : © Domain relational calculus uses domain variables that take values from an attributes domain, rather than for an entire tuple. Formal Definition : © An expression in the domain, relational calculus is of form : ISK. Kp PYRO Nyy os XP Where, Xi Xess X, represents domain variables. P — formula composed of atoms Formulae are build up from atoms using following rules : > Anatom isa formulae IEP, is a formula, then so are 7P, and ). + IEP, and P, are formulae, then so are P,vP,,P,a P, and P, =P, Examples Find the loan number, branch name and amount for loans of over $1200. = {|E loan ( a>1200} Find all loan numbers for loans with an amount greater than $1200. = { 3b,a(E loan a a>1200)} (2) _ Warning : Xerox Photocopying ofthis book is a CRIMINAL Act. Anyone Tound gully LIABLE to Tace LEGAL roceel™ ]

You might also like