Download as pdf
Download as pdf
You are on page 1of 56
. en UNIT SQL AND SCHEMA REFINEMENT PART-A , SHORT QUESTIONS WITH SOLUTIONS QI. Give the basic form of SQL query. Answer + Modal Paper, 1(0) ‘The basie form of SQL query is, SELECT [DISTINCT | ALL] FROM TABLE list WHERE Condition, Here, solumn-list LECT clause is used to query data from a relation present in a database. FROM clause specifies the list of relations that are to be scanned during the evaluation so as to retrieve the desired data. WHERE clause specifies conditions based on which resultant relation is derived. Q2. Explain about DDL and DML languages. May-47(R15), Q1(b) OR What are the SQL statements are used to retrieve and modify the database? ‘Aprilt8(R16), QA(c) (Refer Only Topic: DML) oR Discuss about DDL. (Refer Only Topic: DDL) Answer : May-16{R13), Q1(a) DDL ‘The Data Definition Language (DDL) creates, alters and deletes relations ina database. The DDL commands perform three operations these are, . 1, CREATE 2. ALTER 3. DROP. 1. CREATE: CREATE command.is used to create a table. ‘Syntax: CREATE TABLE table_name 2 ALTER: ALTER command is used to modify the structure of the table or view. ‘Syntax: ALTER TABLE Table_name 3 DROP: DROP command is used to destroy or delete a table. Sy ; DROP TABLE table_name RESTRICT/CASCADE ‘The keywords RESTRICT or CASCADE must always be used with DROP command, SPECTROM ALL-IN-ONE JOURNAL FOR ENGINEERING STQOENTS Sia GROUP Qi 3.2 DATABASE MANAGEMENT SYSTEMS (JNTU-HYDERABAD! pm (li) NOTIN: The negated version of IN operator is NOT IN. Data Manipulation Languages (DML) is used to It returns a true value if an element is not in the giver ‘manipulate data on database using varios operations. set, Otherwise, returns a false value ‘The SQL statements that are used to retrieve and modify Uxampie: SELECT B.erame eae FROM - Employee E 1, SELECT Command: itis considered as the basie SQL WHERE E.cid NOTIN command which is used (o retrieve the information or (SELECT D.Dept_managerid to select specific columns from the tables. Every SQL S Came query starts with the SELECT keyword and is followed FROM Department D by the list of columns that forms the resulting relation. WHERE D.DNo~ 6); ‘The basic format of SQL que “The above statement returns a value true forthe row that Reectaentis contain the names of employees who are not working i" FROM from department number 6. — M from_list wi " Q4, What is meant by nested quer HERE condition; Answer i ay 464813). 18) 2. INSERT Command: This command is used to add the information or column values fo a row in a table. Its | Nested Queries syntay is as follows, A query inside a query i called as nested query, JOSE * query is called as Sub query is usually present it INSERT INTO table_name(@otumn! ,column2,cohumn3,, query is called as sub query. 2 is VALUES(value1 value2,valuc3, 35 WHERE or HAVING clause. In other words the main query INSERT INTO table-name VALUES(valuel, value2, | ‘tori the subquery i called as nested awe - value3....); | Example | UPDATE Command: This command is used to change Trind the names of employees who are working in cor modify the existing column values of row inatable. | 4ePartment number 6 Its syntaa is as follows, Solution UPDATE table_name SET column_name = SELECT E.Ename Sscalar_expression WHERE condition: FROM Employee E 4 DELETE Command: This command is used to delete WHERE EEid IN the existing column values of a row from the table. Its ereren eaameered syntax is as follows, . DELETE FROM tabie_name FROM — Department D WHERE _D.DNo= 6): WHERE con Q3. ei following operators in SQL with Qs. Seca e ee oe sot Ee the () SOME OR (ii) NOTIN. ea jewn the various soareaie operators Answer : May 19080, 008 | vee ved eaijuns ove a seat cia Sener Aggregate operators (functions) improves the dat Fin ead by asubuery or | Teva property of SQL statement, These operators ensbl urn masch wah secu 1 # SUBUEEY OF | the users to summarize the data retrieved from the relation . Basically, the aggregate operators takes the entire column Syntax: SELECT columal FROM table! WHERE data as its argument and generates a result set that ‘summarizs column! (OME (SELECT column! FROM column!= | the column. The following are the different aggregate operato ‘somevalue’); supported by SQL, Example: SELECT The following are the different aggregate operato FROM Employee E supported by SQL WHERE E.salary=SOME (SELECT salary | 1. COUNT: COUNT followed by a column name retur : y a co FROM Employee E WHERE E salary> 15000), the number of tuples in the specified column. The above statement returns a value for the columh | 2, SUM: SUM fol wns he ; . : nameret containing employee's salary greater than 15000, of all the vals ne ped eh Look for the SLA GROUP LOGO ZS on the TITLE COVER béfore youbuY UNIT-3. SQL and Schema Refinement 3. AVG: AVG followed by a column name returns the ‘avernge value of all the values in the specified column, 4. MAX: MAX followed by a column name retums the ‘maxinyum value from the values present in the specified column MIN: MIN followed by # column name relumns the ‘minimum value from the values present in the specified column, Q8. Define Trigger and give an example. Answer: ‘Triggers: ‘A trigger can be defined ns a program that ig executed by DBMS whenever updations are specified on tfe database tables. More precisely, iti like an event which ocesrs whenever 1 change ix done to the tables or columns of the tables. Only NowsDec.-10(R16), 1c) DBA can specify triggers. Example Consider the following trigger deseription wher: trigger “emp-count” counts the number of employees inserted. CREATE TRIGGER emp-count BEFORE INSERT ON EMPLOYEE /* Event */ DUCLARE ) wt INTEGER BEGIN * Aeton *7 L Count: 0 END This example clegrly explains that the trigger must be activated before each ingertion into the employee table and the action to be taken whehever an insertion is made. a7. ? Answer : What is an active databi May-15(R13), 014) Active database is database consisting of set of triggers. “These databades are very difficult to be maintained because of the complexity that arises 1n understanding the effect of these triggers. In such database, DBMS initially verifies whether the particular trigger specified in the statement (that modifies the database) is activated or not, prior to executing the statement. If the trigger is active then DBMS executes the condition part and then executes the action part only if the specified condition is evaluated to true. Is possible to activate more than one trigger within a single statement. In such situation, DBMS processes each of the triguer randomly. The execution of an action part of a trigger may cither activate other triggers or the same trigger that initialized this actign. Such types of trigger that activates itself is called as ‘recursivettigger’. The DBMS executes such chains of trigger in some-pye-defined manner but it effects the ‘concept of understanding the collection of triggers. - Answer + 3.3 8. Whatis schema refinement? Anewér: April-10(R16), O16) Schema refinement is» process of refining the seherre h e probe ed by redundantly storing the ‘0/4 to solve the problems caused by redur ‘hformation. Redundancy in its simplest terms ean be defined as SUA GROUP a | 34 Q11. Explain transitive dependency with an exampl Answer : ‘Transitive Dependency ae eae dependency X—> Yand Y—> Zare said to insitive dependency if there exist a funct X— Z via attribute ¥. area ea aencene Example FDI: Student_ld > Course_Id FD2 : Course_Id > Fee FDS : Student_Id -> Fee ‘The functional dependency FD3 is said to be transitive dependent. Q12. Whats normalization? What are the conditions fequired for a relation to be in 1NF, 2NF? (Modo! Papers, a1(e)| May-19R18), a1(e)) Anower + Normalization Normalization is the process of converting a relation to a standard form by decomposing smaller efficient relations that depicts a good database design. Normalization technique involves a sequence of rules that are employed to test individual relations so that the database can be normalized to any degree. The main objective of normaliza- tion is to refine the design of database in order to remove data ‘maintaining anomalies, reduce data redundancy and to eliminate data inconsistency. Conditions to INF A relation schema is said to be in first normal form if the attribute values in the relation are atomic i.e., there should be no repeated values in a particular column. Conditions to 2NF A relation is said to be in 2NF, if the following two conditions are satisfied, 10) Arelation must be in INF Gi) Anon-key attribute must be fully functionally dependent ‘on primary k Q13, Listthe advantages of nomalized relations over unnormalized relations. Answer : ‘The advantages of normalized relations over unnormal- ized relations are, (i) Normalized relations (tables) does not contain repeating ‘groups whereas, unnormalized relation (table) contains ‘one or more repeating groups. (ii) Normalized relation consists ofa primary key while there is no primary key in unnormalized relation. Normalization removes the repeating group which occurs ‘many times in a table. (iii) DATABASE MANAGEMENT SYSTEMS [JNTU-HYDERABAD] (iv) With the help of normalization process transform unnormalized table to first normal form (INF) bby removing repeating groups from unnormalized tables. (0) Normalized relations (tables) gives the more simplified result whereas unnormalized relation gives more compli- cated results (vi) Normalized relations bring progress in storage effici dataintegrty and scalability. But unnormalized relations cannot improve the storage efficiency and data integrity tency, Mexible (vii) Normalization results in database consist data accesses. Q14. What is second normal form? — may-10(Rt3), 2100) OR Define SECOND normal form. neo May-45(R13), a1) ‘Second Normal Form (2NF) + Arelation is said to be in 2NF if itis in INF and every non-key attribute is fully fimetionally dependent on primary key attribute. A relation is said to be in 2NF if any one of the following conditions are satisfied 1. There should be only one attribute associated with the primary key. 2. There must be no non-key attributes in the relation Non-key attribute must be functionally dependent on the set of primary key attributes ie., partial dependencies must not exist, Example Consider a simple example of STUDENT relation, Student (Student_Id, Class_Id, Name, Course, Time) (Student_Id, Class_Id) is the primary key. Q15. Define BCNF. Write down its basic properti Nov/Dec. -18(R16), 0110) Answer: A relation schema R is said to be in BCNF if the following statements are true for each FD P—> Qima set F of FDs that hold over R. Here, P is the subset of attributes, of R and Q is a single attribute of R. (The given FD is a trivial, ie., QEP (ii) Pisa super key. Atuple in a BCNF relation is considered as an entity or a relationship, described by attributes other than the key The key is used to differentiate each tuple. The structure of such a BCNF relation R can be obtained by representing the attributes of R as square boxes and drawing arcs between the key and the attributes 10 indicate its FDs. Look for the SIA GROUP Loco @ on the TITLE COVER before you Duy 3.5 El-La) Key: Super key, Ay. Ay oon A, : Non-key attributes, 7 Figure: Structure of BCNF Relation indicating ts Fs BNF is, Fred NF iS considered tobe the most desirable normal form with respectto redundancy, since it restricts the detection oftedundaney using only the FD information, Q16. What is the difference between 3NF and BNF? Answer : (Model Papers, Q1(9 | May-A71R13).Q1(N) BCNF 3NF - Ifa functional dependency A —» B is present, 1, | 1fa functional dependency 4 > B is present, then then BCNF allows this dependency in a relation NF allows this dependency tobe ina relation if only if‘4* is a candidate key. and only if, °B" isa primary key attribute and “A’ is not a candidate key. 2. | Arelation in BCNF is also in INF. 2. | Arelation in 3NF need not be in BNF. 3. | Decomposition of BCNF relations is not possible. | 3. | itis possible to decompose any relational schema : into a set of 3NF relations, by using decompositions, that possess certain desirable properties like lossless- join, dependency preservation. 4. | BCNF guarantees that no redundancy can occur | 4. | Thereisa possibility of some redundancy to occur using only the information about functional ‘because every transitive dependency is not dependencies. eliminated Q17. Define lossiess join decomposition with example. Answer + May-17(R15), (6) Lossless-join Decomposition Lossless-join decomposition is one of the properties of decompositions. This dependency is also called as nonadditive or nonloss join dependency. In a more specific way, lossless-join dependency can be defined as the one which generates no additional tuples when the natural “join” operation is performed on the decomposed relation schemes. Example Consider a relation, R(M, N, O) and itis decomposed into two subrelations R(M, N) and R,(N, 0). M[Nio ie | ez) 1 2 5 3 R(M, N, 0) R(M,N, 0) > ROLN RENO) SPECTRUM ALL-IN-ONE JOURNAL FOR ENGINEERING STUDENTS - SAG ae DATABASE MANAGEMENT SYSTEMS {UNTU-HYDERABAD] 36 ___DaTABASE MANAGEMENT SYSTEMS INTE N 2 5 3 Ro) aes oma sya EE ‘The condition for lossless decomposition should be, =R Here, the R,o¢ R, retums R Riva The above decomposition is ion. Nov /Dec.-18(R16), Q1(0) ‘The two properties of decomposition are as follows, (a) Lossless-Join Property This property helps to identify any instance of the ‘original relation from the corresponding instance of the smaller relation attained after decomposition. (b) Dependency Preservation This property helps to enforce constraint on smaller relation in order to enforce the constraints on the original relation. ‘To answer the second question a number of normal forms exists. Every relation schema is in one of these normal forms and these normal forms can help to decide whether to decompose the relation schema further or not. ‘One of the drawbacks of decomposition is that it enforces to join the decomposed relations in order to solve the queries of the original relation. This may result in the performance degradation if such queries are common. In order to improve the performance itis necessary to ignore the problems caused redundancy and decomposition of the relation Q19. Define Multivalued dependencies and join dependency. ‘Apri t8(R16), 0110 OR Write about join dependencies. (Refer Only Topic: Join Dependency) ‘Answer Multivalued Dependencies MVDs are generalization of functional dependencies. They can be represented as, Course —>—» Student May-15(R13), Q4(f) Course —>—> Text book This is read as “student is multi-dependent on course” or “Course multi-determines Textbook”. The meaning of MVD Course —p-—> Student “There exists a set of students corresponding. €ach course Cie. fora course Cand a textbook, B, the set of students hatching the pe (C.B) in CST depends onthe value of C ony. Itis independent of the value B. A multivalued dependency cam be defined as: FX.¥-Zare the atribute sub sets of attribute set of relation A then Yis said to be multi-dependent on Xf for every instance of A,a set of ¥ values matching a given pair (Xvalue, ‘Zvalue) depends only on the X value and does not depend on Z value. ; Join Dependency ‘Ajoin dependency refers toa constraint that is provided coma group of relations over a database schema. For instance, 9 table “S° holds ajoin dependency relationship if multiple tables consisting of similar atributes ofS” are joined so as to recreate the table S. Let My My Mj.M,bea group of relations corresponding to-a relation M. Here, M is said to have a join dependency relationship ie. *(M, My M,.oM) if the following equation satisfies for each relation m of the schema M. Mm = Hyg (8) PS Ty) OS Ryo) hm) Join dependency is said to be trivial if and only if any of the relations M,, My, M,...M, contain all the attributes of the relation schem 220. Describe the inclusion dependencies. ‘Answer = (Modal Papert, 1(f)| May-16(R13), QF Inclusion dependency is a statement containing attributes a A and B in X and Y relations respectively such that 4 is dependent attribute and isa subset of B which is its referenced attribute. Foreign key constraint which allows columns in one relation torefer the columns of a primary key is an example of inclusion dependency. cage ee Look for the SIA GROUP LOGO {Jf} on the TITLE COVER before you b¥Y UNIT-3. sat and ‘Schema Refinement a * PART-B ESSAY QUESTIONS WITH SOLUTIONS 3.1. Sai: QUERIES, CONSTRAINTS, TRIGGERS 3.4.1 Form of Basic SQL Query Q21. What is SQL? List the features of SQL. . Answer : SQL ; ‘SQL (Structured Query language) is a database language which is compatible with RDBMS. It provides an interface to simple relational database. It is a simple portable language that does not require enough learning to work with its syntax and commands. It performs the following functions, (@) Creates tables and database structures. (b) Performs addition, deletion and modification operations on the database structure’. (©) Performs difficult queries to convert raw data into useful information All these operations are performed using the concept of DML (Data Manipulation Language) and DDL (Data Detinition Language), Features 1. SQL is « non-procedural and English-like language containing statements in English sentences. Hence SQL statements are easily understandable, ‘ It minimizes the time required in creating and maintaining the database systems. It isa portable language and can be executed on various computer systems. It gives quick solutions to complex queries. Itenables communication between clients and servers over a network, It's also an interactive query language that allows users to store dita on adhoc bases. sae ee Itenables programmers to write applications for accessing database. Q22. Explain about the basic form of a SQL queries. Answer : April, Set-4, 8(a) Basic form of SQL Query ‘The basic structute of an SQL query is, SELECT [DISTINCT|ALL] Column-list FROM TABLE-list WHERE condition; The above structure of an SQL query consists of following three clauses, @ SELECT (ii) FROM (ii), WHERE. @® SELECT Clause ‘SELECT clause is used to query data from a relation present ina database. The result after executing the SELECT statement is another relation which is derived from the relations specified. The resultant relation consists of list of columns that are desired to be in the result of a query, SELECT clause can be followed by two optional keywords DISTINCT or ALL. Ifthe keyword DISTINCT is used along with the SELECT clause, then the resultant relation doesn’t contain any duplicate rows. On the other hand, if keyword ALL is used, then it specifies that duplicate rows are eliminated from the resultant relation. Generally, asterisk symbol (*) is used to denote “all attributes” of a relation. This clause may even include arithmetic expressions that consists of arithmetic operations ,) that are operating on constant or attributes of tuples. SIAGROUP 5 38 (W) "FROM Clause am sine specifies the list of relaons tat reo eset en, ie the evalution process soa 0 rtive the erent It corresponds to the Cartesian product operation crea Clecbe tis followed by belt that species able Tattle nates from which datas tobe retrieved. This are a. ca in tur be followed by a range variable when the is used more than once inthe tabe-lst (i) WHERE Ciause WHERE clause is used to specify a condition () based on which the resultant elation drived This lation sntaies ‘only those rows that satisfy the given condition. SQL uses logical connectives as well as comparison operators in the WHERE clause. The operand of logical connectives are the expressions consisting of comparison operators. Examples (Consider the following schema, . ‘Employee(Ename, Eid, Esal, Phone, Age, DNo) Department(Dname, DNo, Dept_Managerid) Project(PNo, Pname, Pduration, Plocatin) Query 1 Find distinct names of employee. SELECT DISTINCT Ename FROM Employee; ” Query 2 Find all the employees who are working in department ‘umber 7. SELECT * : FROM Employee E, Department D WHERE D.DNo = 7; Query 3 . Find the names of employees who are working under Project-number 44 and project-location is either Hyderabad or Bombay. SELECT E.Ename, D.DNo, P.Plocation, P.PNo FROM Employee E, Department D, Project P WHERE E Eid - D-Dept_Managerid AND PPNo= 44 AND (PDiocation = ‘Hyderabad’)°> ‘ OR (PPlocation = ;Bombay’); | DATABASE MANAGEMENT SYSTEMS [JNTU-HYDERABAD] 23. What aro the types of languages @ database aystem provides? Explain. OR Givean overview of database languages ~ DDL and DML. Answer: ‘Apri-t0(R), 238) Database Languages “The database languages are called sublanguages. This is because they do not have all the facilities of a full-fledged programmirg languages. Several constructs like selection and iterative statements are not available. The sublanguage has to parts, 1, Data Definition Language (DDL) 2, Data Manipulation Language (DML). DATABASE LANGUAGE, DATA DEFINITION DATA MANIPULATION LANGUAGE LANGUAGE Data definition language is used for designing database schema, Data manipulation languages are used for queries and operations like insertions, deletions etc. 1. Data Definition Language (DDL) Data definition language defines the schema for the da- tabase by specifying entities and the relationship among them, It also says some security constraints. ‘The execution of DDL statements results in new tables, ‘These tables are stored in “system catalog” also called data dictionary. eta dictionary has the information of all the definitions of database schema, low-level data structures, files and records It also maintains the relationship information among various records. Data dictionary provides faster access to database by maintaining certain indexes. Data dictionary also contains meta data that has dla about the data stored in database. Data definition language allows the user to specify the storage and access methods by using a special language called data storage and definition language. 2 Data Manipulation Language (DML) Data manipulation language performs the following ‘operations, i () Insertion of new data i) Deletion of stored data Gi) Retrieval of stored data (iv) Modifying the data, UNIT-3 SQL and Schema Refinement Data manipulations are applied at internal, conceptual and enteral databases, However the level ofeorplento i volved varies. Complex low-level procedures allow efficient access, but extemal procedures focus on ease of usage, there. by incurring low complexity Data manipulation language that involves in retrieval of data is called “query language”. DML are classified based on the retrieval constructs. [beta Nanutarion ania] _ ff, [Procebunat om | Figure: Classification of DML (a) Procedural DMLs Using procedural DML the user can specify what data needs to be retrieved. The user also have to guide as how to retrieve the data, ‘This means that the user has to express the operations that would retrieve the desired data. DML initiates by evaluating these operations. The result of evaluation is again operated until the desired data is retrieved. The DML statements are embedded into high-level languages to perform selective and iterative operations. (>) Non-procedural DMLs Non-procedural languages are also called declarative languages. These languages are easy to lear as the user simply needs to express the desired data. It is up to the database system to choose an ppilinal procedure to retrieve the data. DBMS translates the DML statements into set of procedures and retrieves the data, SQL (Structured Query Language) and QBE (Query By Example) are some of examples of non-procedural DML. 24. Define data manipulation. Explain command used in data manipulation. OR Explain various DML function in SQL with ‘examples. ‘Answer : May-19(R16), 05,6) Data Manipulation Data manipulation is a method of manipulating data on database using various operations. It uses DML for this purpose. DML The Data Manipulation Language (DML) uses the following commands to perform operations in databases, 1. SELECT command 2. INSERT command 3. UPDATE command 4, DELETE command. 39 1. SELECT Command a ymand is mostly used in SQL queries. It is considered wth baie SQL command wich s sed 1 bon the information of to select specifi columns from the tables. Every SQL query starts with the SELECT keyword and is followed by the ist of columns that forms the resulting relation. Syntax, ‘The basic format of SQL query is, SELECT select List FROM from_list WHERE condition; Example SELECT Ename, Eid FROM Employee WHERE Esal > 20000; (a) FROM Clause ‘This clause specifies the names of the tables from which data is to be retrieved. FROM is followed by a set of range values which uniquely identifies a table, when its ‘name occurs more than once, (&) WHERE Clause WHERE keyword is used to specify a condition. All the ‘tuples which satisfy the condition are selected. ‘The various other claysesthat can béxised in the SELECT statement are GROUP BY, HAVING, ORRER BY etc, (©) GROUP BY Clause GROUP BY clause is uséi to grodp the data of a table ina single row or column based én the given grouping, ‘condition. It applies some aggregate functions like MAX, MIN, AVG, SUM and COUNT on group8. ORDER BY Clause Z ORDER BY ctante. ig suithto setrieve tHe Mbt ir particular onde i. athet asdending ot descending oder. (© HAVING Claw é HAVING clause {s similar tothe WHERE cle. it ie used 10 pose the conditions on groups. With WHERE clause, conditions are set on rows and with HAVING clause, conditions ate set on groups. ‘Syntax @® SELECT select ist FROM from_list GROUP BY grouping list ORDER BY ordering list HAVING condition; Example SELECT Ename, DNo, MAX(Esal) FROM Employee GROUP BY Ename ORDER BY Esal DESC HAVING MAX(Esal) > 6000; ee ena eee SPECTRUM ALL-IN-ONE JOURNAL POR ENGINEERING STUDENTS ——)_S. aa Gaus @ STEMS [JNTU-HYDERABAD] ao DATABASE MANAGEMENT SY! Hall tne information 4s to be retrieved from a table then its syntax is as follows, SELECT * FRQM table Example SELECT * FROM Employee 2, INSERT Command This command ic wet. informatio om values Yo a row ina table Ws yea is (ONS INSERT INTO table nami clan, column...) VALUES(valuel value, valves INSERT INTO table name V*LUES(waluel. value2, value3, Example INSERI INTO Lmployee( Eid, Ename, Esal, Age, Phone) VALUES(E-102', “David, 28000, 35+ 44004400), INSERT INTO Employee VALUES(*E-102°, ‘David’, 28000, 35, 44004400), inserted into the tabl own and a row is le. This is done based o ample, it is observed that at any time only a single row is ie. Tis i done base» From the abo slumns. For instance, if the phone number of an employee is not kn the values specified fo the table then the insertion can be done in the following two ways, (INSERT INTO Lniploycettid, Cname, Esal, Age) VALUES(E-104", “Bechkam' 30000, 32, NULL}: (it) INSERT INTO Fruployce VALUESCE-104", ‘Bechkam’, 30000, 32, NULL); While inserting « nev row, the following points must be considered, (a) When columns are defined with NOT NULL and DEFAULT option, then default values must be ossigned to them. (b) When coiumns are defined with NOT NULL option and values are not specified to them then the INSF} fails to petiorm its operation thereby keeping the database unchange. {c)__ When a column is not specified swith NOT NULL option then a null valve is assigned 10 it they shouldn't contain null values i RT comm 3. UPDATE Command This command is used to change or modify the existing colum UPDATE table_name SET column_name = scalar_expression WHERE condition, “The rows that satisfy the condition ofthe WHERE clause are updated based on the assignments given in the SET All the rows in the table get updated whenever WHERE clause is not specified. .n values of a row in a table. Its syntax is as follows, Example UPDATE Employ ce SET Eid = *E-120° WHERE Age = 30; In the above gxample, the Eid of an Employee whose age is 30 is set to ‘E-120". 4 DELETE Command ‘This command is used to delcte the existing column values of a row from the table. Its syntax is as follows, DELETE FROM table name WHERE condition; {All rows, which satisfy the condition of WHERE clause are deleted Example DELETE FROM Eyoployee WHERE Bid = “E-210°; Inthe bo: example all the students whose Eid is “E-210” are deleted from the Employee table. ‘Whenever WHERE clause is not specified, all the rows in a table gets deleted. Its syntax is, : DELETE FROM table_name; Example : 7 DELETE FROM Employee: , In the above example, all rows from the Employee table gets deleted, oe Look for the SLA GROUP LOGO QB on he TITLE COVER befdre you buy UNIT-3. SQL and Schema Refinement aes Q25. Explain various DDL and DML commands. Nov/Dee.-18(R16), 2/6) OR Explain DDL commands with syntaxos (Refer Only Topics Data Definition Lenrgmuage (DIE) oat Model Paper G6ta) Data Definition Language (DDL) ‘The Data Definition Language (DDL) creates, alters and deletes relations in a database. The DDL perfvrms: the following operations, 1 CREATE 2. ALTER 3. DROP. L (CREATE ‘The tables (or relations) in SQL are created using the CREATE TABLE ci wind. Syntax CREATE TABLE table_name (columnt_name datatype [NULL | NOT NULL [WITH DE*AUILT]| UNION). (column2_name datatype [NULL | NOT NULL [WITH DE"AULT} | UNION (ColumnN_name datatype [NULL | NOT NULL [WITH DE [) UNION} [Primary: key definition}, [Alterate_key_definitions}, [Foreign_key_definitions}), In the definition of CREATE TABLE command, column_name is the name of the that the column will hold. The keywords NULL and NOT NULL are optional. These must be checked while inserting data into the table. Ifa column is specified as NULL then a NULL value will be inserted in that column ifthe ser d that column. If column is NOT NULL, then the user riust specify veluc for tnt cohunn otherwise the sysiem does not accept that record and returns an error message. With NOT NULL, two other keywords WITH DEFAUIT or UNION ean also be specified. Both the keywords are optional. 1fs column is NOT NULL WITH DEFAUII, then the sy the default value for that column if the user does uct specify the value. For exampte, the d-fault value f data type 4s 0 and for character data type is a space. If a column is specified as NOT NULL UNIQUE ahen the system doo not low the duplicate values for that column. The last three fines ir the CREATES TASS F cfinetion spesty the primary k alternate key and the foreign key for the new table Example ‘The following statement creates a new table named customer, CREATE Table Customer (cid INTEGER NOT NULL, cname — CHAR(20), aceno INTEGER: fname — CHAR(30) NULL, amt REAL NOT NULL WITH DEFAULT, Primary key(cid)); 2 ALTER ALTER TABLE command is used to modify the structure of the tabie or view. Syntax ALTER TABLE Tabiename ADD [COLUMN] Columnname datatype DROP [COLUMN) Coiumaname RESTRICTICASCADE ADD [CONSTRAINT] Constrain: name DROP [CONSTRAINT] Constraint name RESTRICT/CASCADE [ALTER [COLUMN] SET DEFAULT Defavit option} [ALTER [COL!!MN] DROP DEFAULT] imac aia one Journ Fon BvanEaRING MODHR? ———— umn, data rype isthe type of data eywords s itions that es not insert value for ‘th Alter command following modification can be done, Addition of column Deletion of column, 10m oF constraint Delotion of constraint Setting « default vaiue for a column Unsetting a default value for a column. ALTER TABLE Employee ADD Project_ Number INTEGER © ALTER TABLE Employee ALTER SEX SET DEFAULT 'M’ prop Destroying or deleting a table can be done with the help of DROP command, Syneax DROP TABLE table name RESTRICT/CASCADE Phe Keywords RESTRICT or CASCADE must always be used with DROP command. Example DROP TABLE Department RESTRICT ‘This command deletes the department table if some view ot integrity constraint is referring to it otherwise, this command fails. + DROP TABLE Department CASCADE : tn this case all views and integrity constraint referring to the relation “department” are deleted along with the table Data Manipulation Language (DML) For an: the steps Involved init. OR Discuss the functionality of query evaluation engine. Refer Only Topic: Query: Evaluation) May-15(R13), 200) Answer: ‘Query Processing ‘Query processing is a sequential process of retrieving data from 2 database based on the input by performing ‘several operations. The cost of processing a query is directly propo-tional to the number of disk accesses. There are many sirategies (good strategy, bad strategy) that can be used for processing a complex query. The selection of the best strategy 0 crucial point and therefore requires significant amount of ume io be spent, even if the query is being executed only once, DATABASE MANAG! EMENT sySTEMS [UN TURP MERAGAD) Seercecerearerieay ere ile proces Steps eee the steps considered while processing 4 awe Query parsing and translation 1 oimiaton 3. Query evaluation raing and Transiaion iti itp ase-eared query anid translatio em that is easily Minderstood by the System, The an internal rr ing transtation is tha he G0) CNH by purpose of per! format which is not ‘understood by the system al forms of these, the most wi ely used internal representation is dependen, Igebra. con extended relational al . fore rm tware called ‘Parser’ is responsible for performing the-translation process. This software will carry out the following activities, Verifies whether the query entered is syntactically @ cee ecified in the query i relation name spec’ Wi (iy Nees OS Came ved in cane (iy Construct a parsetre (query-ree) for representing ie query or expression using views Gv) _ Converts the parsetree into relational algebra exresin and if views are used then replace these views with felational algebra expression defining the view. 2. Query Optimization Query optimization is an essential activity of relation DBMS. In this step, the selection ofan efficient query evaluation plan is made. It is the ‘plan consisting of series of primiive operations using which a query can be evaluated. The selection is done based on the estimate of cost associated with ever ‘evaluation plan Its the responsibility of the system to develop a query evaluation plan that reduces the cost incurred while evaluating the query. Practically, its not possible to estimate tbe cost of every individual evaluation plan. Thus, in order to make good cost estimate, optimizes can use statistical information such as size of the relation, the index depth. ‘Therelational query languages that a user uses for creatits a query can either be declarative or algebraic. Declaraté languages are the languages that allow the user to specify st ‘outcomes should be generated from the query. Howevet. it does not specify the way, the system performs its operstio® for generating the desired outcome. Algebraic languages ** the languages that perform algebraic transformation. Once the user has specified the desired query language, the optimize then easily generate multiple query evaluation plan. An¢ tro" ‘these plans, the plan with minimum cost can be selected, 3. Query Evaluation ‘eben query evaluation step, in aduition to specifyi"é al algebra expression, it is necessary to annote thes ‘expressions using the instructions that determine the #3) ! evaluating each operation. Such an abe eee . Such an expression is refer ‘evaluation primitive’ : Look for the SA GROUP LOGO {3 on the TITLE COVER bethé you buy UNIT-3_ SQL and Schema Refinement The purpose of such annotation evaluation plan selected by the optimizer i Query using the plan. Once the query is ev that it speci aluated, the result is retumed ack tothe query. (| Cel | Query paris raring at Aton SIGE || [[Pesenseewee | | es [Eatin cae Query iad [owe Figure: Steps for Query Processing 8 the algorithm of index to be used for a specific operation. The query is supplied as input to the query execution engine that is responsible for evaluating the 227. Explain with example the significance of DISTINCT keyword. ‘Answer : Consider the following three relations. Employee Fid_| Ename | DNo | Esat_| Age | Phone | tor |. Join | 2 | 35000 | so | 2as7eo12 | 100 Harry 3 18000 29 33273120 | 107 Henry 7 22000 3 55809192 . 7 David S 30000, 41 23535135 108 Sam 1 25000 32. 24532121 102 Henry 2 22000 35 24578290 120 ‘Smith 4 20000 20 56408489 122 David 6 18000 25 24517635, Department Diocation Hyderabad Secunderabad Bombay w is (JNTU-HYDERABAD} 3.14 DATABASE MANAGEMENT SYSTEM! Project Pduration | Project_Managerid 9 Months 4 Months 1 Months 25 Months |_9 Months Query Select the names and salaries of the employees, whose salary is greater than 20000. Solution SELECT DISTINCT E.Ename, E.Esal FROM Employee E WHERE E.Esal > 20000; The result of this SQL statements is as follows. | Ename | Esal Join | 35000 Henry | 2000 David | 30000 sam _| 25000 Tat Result using DISTINCT Keyword The above table does not contain al the tuples whose salary is greater than 20,000. The tuple with Ename “Henry” is repeated ‘buts displayed only once. This is due to the use of DISTINCT keyword. If this keyword isnot used then table is resulted. ‘The omission of DISTINCT keyword resulted in arow (Henry, 22000) which is repeated twice. This is called as multiset of rows, It can be defined a a set consisting of unordered elements which may consist of many copies of same element but the total rmumber of copies ofthe element is important. For example the set 1,21,1,) and (2,1,1,1) are same multset. Both contains three copies of “I” and only one copy of 2". But the multiset (1,2.2,1) ‘titeria to differentiate between two multisets, 28. Consider the following relations, Student(snum: integer, sname: string, major: string, level: string, age: integer) Class(name: string, meets at: time, room: string, fd: integer) Erolled(snum: integer, Ename: string) Faculty(fid: integer, fname: string, deptid: integer) Write the following queries in SQL, (0) Find the names of al juniors (level = JR) who are enrolled in a class taught by Leach. (ll) Find the age of the oldest student who is either a history major or enrolled in a course taught by I teach. Ail) Find the names ofall classes that either meetin a room R128 or have five or more ‘students enrolled. led in two classes that meet at the same time. Answer April-14, Set-3, Q7(a) © SELECT Stsname FROM Student St, Class Cl, Enrolled Er, Faculty F WHERE Stsnum = Ershum AND Erename = ‘name AND Clfid = Ffid AND F.fitame = ‘Lteach* \fid = Fs =‘Lteach’ AND St.level = “JR () SELECT MAX (Stage) ae FROM Student St WHERE (Simajor = “HISTORY") OR St snum IN(SELECT Er.Snum FROM Class Cl, Enrolled ER, Faculty F WHERE Exename = twice UNIT-3 SQL and Schema Refinement a aii) w Q29. Write queri SELECT Clname FROM Class C1 WHERE Cl.room = ‘R128 OR Cliname IN(SELECT Er. Came FROM Enrolled Et GROUP BY Er, Came HAVING COUNT (4) >= 5) SELECT DISTINT St.sname _, FROM Student St WHERE Stsnum IN(SELECT Er, snum FROM Enrolled Erl, Enrolled Er2, Cass Cll, Class C12 WHERE Er snum AND Erl.ename = Cll name AND Er2.ename = C12.name AND Cll time = C12.time); for the following using the given information, .snum AND Erl.ename <> Er2.ename EmpName | DOB | DOJ [EmpSalary | Bonus [por Buelin 06-12-1983 |07-08-2005 15000 600 07-08-2055 ‘Andy 12-01-1970 |06-12-1973 | 20000 | 1200 | 06-12-2043 Lubber 07-08-1985 |12-04-2006 13000 500 12-04-2056 Zobra 08-02-1960 [07-03-1982 | _ 25000 _| 1500 _| 07-03-2032 (a) Find total salary of employees from emp table. (b) Find months between employee DOJ and DOR from emp_schema. (€) Create new salary table using the empname and empsalary from existing table. (d) Arrange empnames in ascending and descending order Answer @ () © @ ‘Select sum(EmpSalary) from Emp_schema; Select ((Month(DOR) - Month(DO1)) + [(Year(DOR) - Year(DO}))}* 12] from Emp_schema; Create table salary as (select EmpName, EmpSalary FROM Emp_schema); Select * from Emp_schema ORDER BY EmpName ASC Select * from Emp_schema ORDER BY EmpName DESC; 3.1.2 UNION, INTERSECT and EXCEPT Q30. Discuss about set operators with suitable examples. Answer : Model Papers, 6(a) Set Operators Set operators merge the result set of two different queries into a single result set. Before, using the set operators, it is necessary to ensure that every select statement must have same number of columns and every column belongs to same datatype family. Following are the three commonly used set operators in SQL. @ (UNION (ii) INTERSECT iii), EXCEPT. UNION UNION operator combines two or more result sets into single result set. Though UNION operator in SQL, have same functionality as join operation in relational algebra, the former generates a single result set by merging multiple result sets, wherees the latter extends the row horizontally. There are two forms of UNION operator, (@) UNION [DISTINCT] (b) UNION ALL. SPECTROM LAN-ONE JOURNAL FOR ENGINEERING STODENTS Sia GROUP 3.16 UNION [DISTINCT] This operator returns a resul r ions result set that doesn’t contain any Syntax SELECT column! cofumn2, colamn3 ...FROM Tablet UNION [DISTINCT] SELECT column, cohumn?, column3.... FROM Table2 Example ELECT E.ename, D.DNo, D.PNo FROM Employee E, Department D WHERE E.ceid ~ D. Dept_managerid AND D.PNo= 44 AND D Divcation = “Hyderabad” UNION DISTINCT SELECT E L.ename, DI.DNo, DI.PNo FROM Employce E1, Department D1, WHERE El.cid = D1. Dept_managerid AND D1.PNo = 44 AND DI.Dlocation = ‘Bombay’: The above statement lists the unique names of the employees who are working on project number 44 and project location is either Hyderabad or Bornbay. (b) UNION ALL This UNION operator returns the result set that conta duplicate rows. Syntax SELECT Column, Column2, Columns... FROM Table UNION ALL SELECT Columnl ,Column2, Column3.... FROM Table2 Example SELECT E.ename, D.DNo, D.Dlocation FROM Employee E, Department D WHERE E.eid = D.Dept_managerid AND D.PNo = 44 AND D.Diocation = “Hyderabs UNION ALL SELECT El.ename, D1.DNo, D1.PNo FROM Employee El, Department DI WHERE El.eid = D1.Dept_managerid AND D1.PNo = 44 AND D.Dlocation = ‘Bombay’; The above statement lists all the names of employee (including duplicate names) who are working on project number ‘44 and project location is either Hyderabad or Bombay. UNION operators are generally used in many data warehouse applications because the relations in these applications are not perfectly normalized. This operator doesn’t the order of rows (i.e., rows of second relation may ‘appear before the rows of first relation). However, if specific order is to be followed then ORDER BY clause can be used with UNION operator. Look for the SIA GROUP LOGO DATABASE MANAGEMENT SYSTEMS [JNTU-HYDERABAD) (i) INTERSECT INTERSECT operator combines the result sets of two different queries into a single result set that contains only the columns which are common in both relations. INTERSECT ‘operator in SQL is similar to the inner join operator in relational algebra, but the difference is thatthe former finds the common ‘columns vertically whereas the latter finds it horizontally. The following are the two forms of INTERSECT operator, (@)_ INTERSECT [DISTINCT] (b) INTERSECT ALL. (®) INTERSECT [DISTINCT] This operator removes dupli result set. te rows from the final Syntax SELECT columnl, column2, column3,.... FROM Table! INTERSECT [DISTINCT] ‘SELECT column!, column2, column3,.. . FROM Table2 Example SELECT E.ename FROM Employee E WHERE E.DNo = 4 INTERSECT SELECT El.ename FROM Employee El WHERE E1.DNo = 6; The above statement lists the unique names of employees who are working for department 4 and 6. (b) INTERSECT ALL This operator doesn’t remove dy final result set. Syntax ‘SELECT column!, column2, column3.... FROM Table | INTERSECT ALL SELECT column!, column2, column’... FROM Table? Example SELECT E.ename FROM Employee E WHERE E.DNo=4 INTERSECT ALL SELECT El.ename FROM Employee El WHERE E1.DNo=6; “|” ‘The above statement lists all the names of employe% (including duplicate nanie8) who are working for department 4 and 6, , ‘on the TITLE COVER before you buy ste rows from the UNIT-3 SQL and Schema Refinement EXCEPT EXCEPT operator combines the multiple result set Of two different queries into single result set that contain the ‘unmatched rows present in the result set of first relation, but ‘not in the result set of second relation. This operator is similar to" Outer join” operation but the difference is that the EXCEPT finds the unmatched rows vertically whereas the outer join finds the unmatched rows horizontally. The two forms of EXCEPT ‘operator are, (a) EXCEPT {DISTINCT} (b) EXCEPT ALL. (a) EXCEPT [DISTINCT] This operator returns a result set that doesn’t contain any duplicates. Syntax SELECT column| , column2, column3.... FROM Tablel, EXCEPT [DISTINCT] SELECT columnt , column2, column3.... FROM Table2 Example SELECT D.Dname FROM " Department D WHERE D.PNo= 44 INTERSECT SELECT D1.Dname FROM — Department DI WHERE D1.PNo=55; The above statement lists the unique names of department that are controlling the project number 44 not project number 55. (b) EXCEPT ALL This operator returns a result set that contains duplicate rows, ‘Syntax SELECT columnl,,cotumn2, column3,.... FROM Tablel EXCEPT ALL SELECT column! ,column2, column3.... FROM Table2 Example SELECT D.Dname FROM — Department D WHERE D.PNo=44 EXCEPT ALL SELECT DI.Dname FROM Department DI ' WHERE DIPNo=55; The above statement ists all the departments (including duplicate departments) that are controlling the project number 44 not project number 55. Q31. Explain the various with examples. ‘Answer t Set Comparison Operators Set comparison operators are used to perform comparisen between two different SQL queries, The result of comparison is either True, False or Unknown, The following are the diffrent ‘et comparison operators supported by SQL, @ Gi) ANY Git). ALL (iv) EXISTS. ® IN This comparison operator returns:a value true if a” clement is in the given set, otherwise, retums a value fal Example SELECT E.ename FROM Employee E WHERE. E.eid IN (SELECT D.Dept_managerid FROM Department DWHERE D.DNo ~ 6); ‘The above statement returns a value true for the row that contains the names of employees who are working in departure number 6, The negated version of IN operator is NOY IN. This ‘operator checks if an element is not present in the given set Example SELECT E,ename FROM Employee £ WHERE E.cid NOT IN (SELECT D.Dept_managecic FROM Department D WHERE D.DNo=6); . The above statement retums a value true for he row that contain the names of employees who are not workiny in department number 6, (i) ANY This operator returns the value true if there is aticact« record that satisfies the given condition, otherwise, retuens fst Example SELECT E.ename FROM Employee E WHERE E.Esal> ANY (SELECT E1.csai FROM Employee El WHERE El.ename = ‘Henry’); In this example, E1.esal is calculated for the subguery and all the tuples retrieved are compared with E.csal. The tupte which returns true is the desired result. E.esal>AN’Y returns fu if there are no such employees whose salary is greater than tha of Henry. SIA GROUP {jp WHERE B2.cname < Henry’); nen 2 sal! rte yan pie reiieved are Compared with Esa. Ihe eal ‘of all the employees named Her, eI sal, then (ale a Henay” i rear than Esa, then Re onherwise value false i etumed ay EXISTS operator is a test for checking wheiher the set of tuples satisfying the conditions is aot null, The operator reviirns the evalusiing subquery is non-empty (ie., ms at Teast one row that is not nuli and the given condition). Otherwise, a value false is CT Eename FROM Employee E WHERE EXISs. (SELECT * FROM Department D WHERE D.DNo=6 AND Ds The above statement returns a value true for the set of tupies which eatisfies the condition D.DNo = 6 AND D.Dept_ manageiid = E eid is not empty. The negated version of EXISTS operator is “NOT EXISTS". thet checks whether the set of tuples which satisfies the condition is emoty. D.Dept_managerid Example Inthe above exaxaple, “NOT EXISTS” operator retrieves the st of tupie for which a value true is retumed i. the names Femplovees who 27¢ not working in department number 6. Q52. Explain the foitowing operators in SQL with examples, () SOME (i) ON (lit) EXCEPT (iv) EXISTS. May-17(R15), Q4(b) OR DATABASE MANAGEMENT SYSTEMS [JNTU-HYDERABAD} Explain the following operators in SQL with examples, () SOME aN (i) EXCEPT (iv) UNION. Answer : ) SOME "SOME" operator is generally used in WHERE clause {or verifying whether the value ofa specific column match with set of values returned by a subvery oF not. Syntax Apritsayn6), Q8(b) SELECT column FROM tablet WHERE columnt ~ SOME (SFLECT column! FROM columnt= ‘somevatue’); Example SELECT * FROM Employee & WHERE E.salary = SOME (SELECT salaty FROM Employee £ WHERE E.salary > 15000) ‘The above statement returns a value for the column containing employee's salary greater than 15000. @ oF For answer refet Unit-Ill, Q31, ‘Topic: IN. Gi) EXCEPT For answer refer Unit-II1, Q30, Topic: EXCEPT. (iv) EXISTS For answer refer Unit-IIJ, Q31, Topic: EXISTS. (yj — UNION For answer refer Unit-II1, Q30, Topic: UNION. 3.1.3 Nested Queries, Aggregation 33. Whatis anested query? Explain with an example. Answer = Model Paper-il, 0646) Nested Queries A query inside a query is called as nested query. Imer query is called as sub query. Sub query is usually presen it WHERE or HAVING clause. In other words the main qvety that contains the subquery is called as nested query. Example Find the names of employees who are working i? departinent number 6, Solution SELECT E.Ename FROM Employee E WHERE E.Bid IN (SELECT D.Dept_Managerid FROM Department D WHERE D.DNo eee Look for the SIA GROUP Loco QBon the TITLE COVER bua you buy UNIT-3 SQL and Schema Refinement ‘The execution of this nested subquery is done in following manner, (The inner query is executed first, SELECT ——_D.Dept_ Manager) FROM DepartmentD | Subquery WHERE —D.DNo=6 ‘This query retrieves the Dept_Managerid of all the ‘employees whose DNo = 6, (il) Next, the DBMS checks the presence of resultant value of Dept_Managerid in employce table. If, it exist thon it displays the result for that id (ie., the Ename) ‘The main query that contains the sub queries in called as outer query The IN keyword can also be replaced with NOT IN Keyword. In this case, it checks for the tuples which are not present in the given relation. Example: Find the employce who are not working in dept number 6, SELECT E.Ename FROM — Employee E WHERE E.Bid NOT IN (SELECT D.Dept_Managerid FROM Department D WHERE D.DNo = 6): Q34. With an example, explain the optimization of nested sub-queries. Answer : Optimization of Nested Sub-queries Nested sub-queries are placed under the “WHERE” clause in the form of parameterized function, which returns a single value or set of values. Basically, the parameters passed within the functions are the variables (correlation variable) derived from the outer fevel query. The evaluation of nested query is done by initially computing the cross product in the outer “FROM” clause. After computing the product, the predicates in the “WHERE” clause are tested for every individual tuple in the resultant product. Such way of evaluating query consisting of nested sub-query is referred to as correlated evaluation. The drawback of this evaluation technique is that itis inefficient as more disk input/output are required. This is because, every sub-query is evaluated separately by considering every tuple in the outer level query. ‘Therefore, to overcome this issue, SQL uses an optimizer that convert nested sub-queries into joins wherever it is possible toperform such conversion In situation where conversion is not possible, these SQL optimizer maintains each of the sub-query as separate expression and then optimizes each query separately. ‘Once every sub-query is optimized, correlation evaluation is performed so as to evaluate the sub-queries. Example Consider the following query (Q,) SELECT sid ~ FROM Sailor, Reserves WHERE Sailorsid = Reserves.sid; 3.19 Iisa simple nested sub-query that is moved direetly into the FROM clause of outer relation. Ifa nested sub-query cannot ‘move tothe “FROM” clause, hen in such situation, a temporary relation is created that maintains the information about the result general “rp. esingaiested y without selection. This relation is «. ated using correlation variable from the outer level 4uery. Then, this relation is combined with outer level query using join operation. Consider the following instance of query. SELECT .. FROM 1 WHEREC, AND EXISTS(Select * FROM T, WHEREC,), In the above query, C. is a conjunction of simple predicates and can be rewritten as, CREATE TABLE Tab! AS SELECT DISTINCT Att FROM C, WHERE SELECT FROM C,, Tab) WHERE C, AND C3 Here, C’, consists ot predicate nC, without the selection consisting of correlation variable and C} redefines selection with correlation variable. “Att” specifies all attribute used! in selection consisting of correlation variable Query(Q,) can be transformed to, CREATE TABLE TabI AS SELECT DISTINCT sid FROM Reserves SELECT sid FROM Sailor, Tab! WHERE Tab] sid = Sailor sid Q35. Write the following queries in SQL using nested queries concept for the following schema, Sailors(sid: integer, sname: string, ratin ger, age: real) Boats(bid: integer, bname: string, color: string) Reserves(sid: integer, bid: integer, day: date) (i) Find the names of sailors who have re- served both red and green boat. (i) Find the names of sailors who have re- served ail boats. (iii) Find the names of sailors who have not reserved red boat. (iv) Find sailors whose rating is better than some sailor called Raghu. ao SPECTRUM ALL-IN-ONE JOURNAL FOR ENGINEERING STUDENTS Sia GROUP

You might also like