INTRODUCTION TO SQL AND ITS CONCEPTS PRACTICE QUESTIONS STATE TRUE OR FALSE 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. SQL is a programming language. Unique is used to eliminate the duplicate rows from the output in SQL query. Delete command deletes the table structure and Drop command deletes the data from a SQL Table . Null (unavailable and unknown) values are entered by the following command: INSERT INTO TABLE_NAME VALUES (“NULL”); Foreign key column derives its value from the primary key of the parent table. ALTER TABLE command is used to modify the structure of the table. DML commands are used to define a database, including creating, altering, and dropping tables and establishing constraints. Unique and Primary key constraints are the same. NOT NULL is a constraint that can be defined only at the column level. DDL is similar to a computer programming language for defining data structures, especially database schemas. The condition in a WHERE clause in a SELECT query can refer to only one value. The rows of the result relation produced by a SELECT statement can besorted but only by one column. The WHERE clause is used to specify filtering conditions for groups. The SQL statement: SELECT salary + Comm AS Total FROM Emp; adds two fields salary and comm from each row together and lists theresults in a column named Total. The BETWEEN operator includes both begin and end values. Logical operators and Relational operators cannot be used together. Update and delete statements are DDL statements. 19. When multiple operators are used in a SQL Query, low 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. precedence operators are evaluated in last. A user may specify two or more columns as using the SELECT – DISTINCT clause MIN and MAX can only be used with numeric columns. The SQL keyword GROUP BY instructs the DBMS to group together those rows that have the same value in a column SUM () function is used to count the total number of records in a table COUNT () function ignores null values while counting the records. COUNT(*) function ignore duplicates and null values while counting the records. MAX() function returns an integer field. You can combine all the records that have identical values in a particular field on a group of fields by using ORDER BY statement. To filter the conditions for groups, WHERE clause is used. Group functions can be applied on any data typesi.e numeric, data, string. Any attribute which is present in the having clause without being aggregated must not be present in the group by clause. We can rename the resulting attribute after the aggregation function has been applied. To avoid a Cartesian product, always include a valid join condition in a WHERE clause. Understanding the primary and foreign key relationship is not important to join on the correct columns. COUNT(Fieldname) tallies only those rows that contain a value; it ignores all null values. 1. 2. 3. 4. 5. 6. ASSERTION & REASONING A Primary Key is used to uniquely identify a record in a relation. R: A Primary Key cannot have duplicate value. A: Single row functions work with a single row. R: A single row function returns aggregated value. A: All the candidate keys are Primary Key. R: Primary Key is used to uniquely identify a record in a relation. A: Foreign Key is not used to uniquely identify a record in relation. R: Foreign key can take NULL values A: NULL is Special value that is stored when actual data value is unknown for an attribute. R: Foreign key can take NULL values A: Each attribute in a relation has a unique name. R: Sequence of attributes in a relation is immaterial. A: 7. 8. 9. 10. 11. 12. 13. 14. A: Select Avg(charges) from Hospital; Output: 166.666667 R: Avg() includes NULL values. A: A unique key cannot serve the purpose of a Primary Key R: A unique key attribute can hold null value A: Update is a DDL command. R: DDL commands are used for defining the schema of the database. A: Create cs database; R: Create database database_name help us to create database. A: Delete is DML command R: Delete command deletes the table from a database A: Float datatype cannot be used for storing names R: Char(n) datatype can be used for storing names A: Drop is not a DML command R: Drop is a TCL command A: Data definition language. Consists of commands used to modify the metadata of a table. For Example- create table, alter table, drop table. R: Data manipulation language. Consist of commands used to modify the data of a table. For Example-insert, delete, update. 15. A: Suppose there are suppliers from 30 different cities. 16. 17. 18. 19. 20. 21. 22. 23. A person wants to list only those records of supplier table who belongs to 'Goa', 'Chennai' R: IN operator used in SQL queries to specify the list of | values for searching. A: DELETE is a DML command and used when we want to remove some or all the tuples from a relation. R: DROP is a DDL command which removes the named elements of the schema like relations, domains or constraints and you can also remove an entire schema using DROP command. A: ALTER TABLE table_name ADD column_name datatype. R: Alter table help us to modify the data values of a given table. A: DELETE FROM relation_nameWHERE condition. R: DELETE is a DML command and used when we want to remove some or all the tuples from a relation. A: Between operators produces a result set based on expression within a range. R: An expression can be written using >= and <= operators equivalent to Between Operator A: All candidate keys can be used as a primary key. R: We can use more than one candidate key as a primary key A: Delete, Drop and Truncate are examples of DDL Commands. R: DELETE operations can be rolled back (undone), While DROP and TRUNCATE operations cannot be rolled back. A: The keyword DISTINCT is used with SELECT command. R: DISTINCT keyword eliminates duplicate rows A: The LIKE is a Logical operator in SQL is used to search for character string with the specified pattern using wildcards in a column. R: There are three wildcards (%), (_) and (#) used in SQL. 24. A: Cardinality of the resultant table of Cartesian Product of 25. 26. 27. 28. 29. 30. 31. 32. two tables will be the product of the cardinalities of these two tables. R: Cartesian product generates all possible combination of two tables A: Count(*) and Count(Column Name) returns same outputs. R: Null values are not counted by Count() A: Select Dept, count(*) from hospital group by Dept where count(*)>1; Output: Error R: Exactly one patient admitted in each Dept. A: Select Max(Name) from hospital; Output: Error R: Max( ) can only be used with numeric columns A: SQL does not permit distinct with count(*) R: SQL does not permit distinct with count(*) but the use of distinct is allowed with max and min A: GROUP BY clause and ORDER BY clause are different. R: GROUP BY clause used for grouping of data and ORDER BY clause used for sorting of data. A: Distinct Clause is used to eliminate duplicate values from a result set based on a SQL Query. R: The SQL ORDER BY clause can be used with the DISTINCT clause for sorting the results after removing duplicate values. A: Delete command is used to remove rows or records from table. R: This command is used to remove records along with structure of the table from database A: In SQL, the aggregate function Avg() calculates the average value on a set of values and produce a single result. R: The aggregate functions are used to perform some fundamental arithmetic tasks such as Min(),Max(), Sum() etc… 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. OBJECTIVE TYPE QUESTIONS (MCQ) A relational database consists of a collection of (a) Tables(b) Fields(c) Records(d) Keys Which one of the following is commonly used to define the overall design of the database? (a) Application program (b) Data definition language (c) Schema (d) Source code What is the degree and cardinality of a SQL table? (a)Number of columns and Number of rows (b) Number of rows and Number of columns (c) Number of keys and Number of constraints (d)None _____key is used to join two relations in RDBMS? (a)Primary Key (b) Candidate Key (c) Foreign Key (d)Unique Key An attribute in a relation is a foreign key if it is the _____ key in any other relation. (a) Candidate (b) Primary (c) Super (d) Sub The term _________ is used to refer to a record in a table. (a) Attribute (b) Tuple (c) Field (d) Instance Which of the following will remove the primary key from MySQL table? (a) remove (b) alter (c) drop (d) update A/An ____________ in a table represents a logical relationship among a set ofvalues. (A) Attribute(B) Key(C) Tuple(D) Entry The term _________ is used to refer to a record in a table. (A) Attribute(B) Tuple(C) Field(D) Instance Which of the following attributes cannot be considered as a choice for primarykey? (a) Id(b) License Number(c) Dept_Id(d) Street Consider the table with structure as : Student (ID, name, dept_name, tot_cred) In the above table, which attribute will form the primary key? (a) Name (b) Dept(c) Total_credits(d) ID The term ____________ is used to refer to a field in a table. (a)Attribute (b) Tuple (c) Row (d)Instance For what purpose the DML is provided? (a) Addition of new structure in the database (b) Manipulation & processing of the database (c) Definition of the physical structure of the database system (d) All of the above 14. 15. 16. 17. 18. 19. 20. 21. Which of the following data type will be suitable for storing the name of students? (a) int (b) varchar(n) (c) char(d) None of the above Consider the following table description of a table study. Which of the following is false based on this description? (a) The values of the roll column will never be repeated. (b) The mark column will always take a value equal to 10. (c) Name column may take NULL values. (d) The roll column will never take NULL values. What is the format used for storing date using date datatype? (a) dd-mm-yy (b) dd-mm-yyyy (c) mm-dd-yyyy (d) yyyy-mm-dd Consider the following tables and their respective degree and cardinalities in a database called SCHOOL: Select the degree and cardinality of the Cartesian product of the tables STUDENT X TEACHER from the following options: (a) 30 7500 (b) 200 325 (c) 30 325 (d) 200 7500 Which of the following constraints can be used if we don‟t want user to leave the field blank while inserting data? (a) “NULL” (b)not null (c) “Unassigned” (d) unique key Which of the following data type will be the best choice for storing price of anytime? (a) string (b) int (c) date (d) float Which is not a constraint in SQL? (a)Unique (b) Distinct (c) Primary key (d) Check The term "SQL" stands for (a) Standard query language (b) Sequential query language (c) Structured query language (d) Server-side query language 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. .............. Command helps to fetch data from relation. (a)Use (b) Show (c) Fetch (d)Select .................. Command helps to open the database for use. (a)Use (b) Open (c) Distinct (d)Select Which is the subset of SQL commands used to manipulate database structure including tables? (a) DDL (b) DML (c) Both (a) and (b) (d) None Which of the following is NOT a DML command? (a) SELECT (b) DELETE (c) UPDATE (d) DROP Which of the following sublanguages of SQL is used to define the structure of the relation, deleting relations and relating schemas? (a) DDL (b) DML (c) Query (d) Relational Databases Which of the following is/are the DDL statements? (a) Create (b) Drop (c) Alter (d) All of these Which command we use to create a database in MySQL. (a) Select database from MySQL; (b) Create database databasename; (c) Use databasename; (d) Update database; Sonia wants to see all the databases are available in her MySQL software. Which command is useful for her? (a) Show databases; (b) Show database; (c) Show tables (d) Show database_name; Goni wants to do some work with her database. She is confused about how to write commands to use the required database. Choose correct option (a) Required database; (b) Use database; (c) Use <databasename>; (d) Required <databasename> To show all the tables of a given database what will be the command? (a) Use database_name; shows tables; (b) Use database_name; show tables; (c) Required database; show tables; (d) Required database; shows tables; Consider the following SQL statement. What type of statement is this? CREATE TABLE employee (name VARCHAR, id INTEGER) (a) DML (b) DDL (c) DCL (d) Integrity constraint In the given query which keyword has to be inserted? INSERT INTO employee______(1002, “Kausar”, 2000); (a) Table(b) Values(c) Relation(d) Field 34. 35. 36. 37. 38. 39. 40. 41. 42. Which command shows the table structure of table emp? (a) Select * from emp; (b) Show all from emp; (c) Desc emp; (d) Des emp; An attribute A of datatype varchar(20) has the value "Keshav". The attribute of B data type char(20) has value "Monisha". How many characters are occupied in attribute A and attribute B? (a) 20,7 (b) 7,20 (c) 9,6 (d) 6,9 The SQL keyword(s) ________ is used with wildcards. (a) LIKE only (b) IN only (c) NOT IN only (d) IN and NOT IN If column “Marks” contains the data set {25, 35, 25, 35, 38}, what will be the output after the execution of the given query? SELECT MARKS (DISTINCT) FROM STUDENTS; (a) 25, 35, 25, 35, 38 (b) 25, 25, 35, 35 (c) 25, 35, 38 (d) 25, 25, 35, 35 Which of the following is true about the SQL AS clause? (a) The AS clause in SQL is used to change the column name in the output or assign a name to a derived column. (b) The SQL AS clause can only be used with the JOIN clause. (c) The AS clause in SQL is used to defines a search condition. (d) All of the mentioned The __________clause of SELECT query allows us to select only those rows in the results that satisfy a specified condition. (a)Where (b) from (c) having (d)like Which of the following is not a SQL Logical Operator? (a) = (b) and (c) or (d) not This SQL query selects _______? SELECT name FROM Emp WHERE salary IS NOT NULL; (a) Tuple with null values (b) Tuples with no null values (c) Tuples with any salary (d) All of the above To delete a database _________________command is used (a) Delete database database_name (b) Delete database_name (c) Drop database database_name (d) Drop database_name 43. 44. 45. 46. 47. 48. 49. 50. 51. Which of the following is using wrongsyntax for a SELECT query in SQL? (a) SELECT * WHERE RNO>100 FROM STU; (b) SELECT * FROM STU WHERE RNO>100; (c) SELECT * FROM STU WHERE RNO BETWEEN 100 AND 200; (d) SELECT * FROM STUDENT WHERE RNO IN(100,101); Which operator is used to compare a value to a specified list of values? (a) Between (b) All (c) In (d) None of the above What will be the order of the data being sorted after the execution of given query SELECT * FROM STUDENT ORDER BY ROLL_NO; (a)Custom Sort (b) Descending (c) Ascending (d) None of the above (a) In an SQL table, if the primary key is combination of more than one field, then it is called as _____. (b) _________ command is used to make an existing column as a primary key. Identify the correct command SQL query which is expected to delete all rows of a table TEMP without deleting its structure? (a) DELETE TABLE TEMP; (b) DROP TABLE TEMP; (c) REMOVE TABLE TEMP; (d) DELETE FROM TEMP; Consider the following SQL statement. What type of statement is this? SELECT * FROM Employee ; (a) DML (b) DDL (c) DCL (d) Integrity Constraint The data types CHAR (n) and VARCHAR (n) are used to create ____and _____ length types of string/text fields in a database. (a) Fixed, Equal (b) Equal, Variable (c) Fixed, Variable (d) Variable, Equal The pattern „- – – ‟ matches any string of ________ three character. „- – – %‟ matches any string of ____ three characters. (a) Atleast, Exactly (b) Exactly, Atleast (c) Atleast, All (d) All, Exactly Which of the following will display information about all the employee table, whose names contains second letter as "A"? (a) SELECT * FROM EMP WHERE NAME LIKE "_A%"; (b) SELECT * FROM EMP WHERE NAME LIKE "%A_"; (c) SELECT * FROM EMP WHERE NAME LIKE "_ _A%"; (d) SELECT * FROM EMP WHERE NAME="A%" 52. 53. 54. 55. 56. 57. 58. 59. Which of the following SQL command will help in incrementing values of FEES column in STUDENT table by 10%? (a) UPDATE STUDENT ASSIGN FEES=FEES*1.1; (b) UPDATE STUDENT SET FEES=FEES*1.1; (c) UPDATE STUDENT SET FEES=FEES*10%; (d) UPDATE STUDENT SET FEES 10%; When the wildcard in a WHERE clause is useful? (a) When an exact match is required in a SELECT statement. (b) When an exact match is not possible in a SELECT statement. (c) When an exact match is required in a CREATE statement. (d) When an exact match is not possible in a CREATE statement Which command is used to change the definition of a table in SQL? (a) create (b) update (c) alter (d) delete ALTER, UPDATE, DELETE,DROP ____command is used to add a new column in a table in SQL. (a) update (b) remove (c) alter (d)drop What does the following query do? UPDATE EMPLOYEE SET SALARY=SALARY * 1.10; (a) It increases the salary of all the employees by 10% (b) It decreases the salary of all the employees by 10% (c) It increases the salary of all the employees by 110% (d) It is syntactically correct. Which of the following functions are not performed by the “ALTER” clause? (a) Change the name of the table (b) Change the name of the column (c) Drop a column (d) All of the mentioned Which command to use in order to delete the data inside the table, and not the table itself: (a) DELETE (b) TRUNCATE (c) Both TRUNCATE & DELETE (d) DROP Choose the correct command to delete an attribute A from a relation R. (a) ALTER TABLE R DELETE A (b) ALTER TABLE R DROP A (c) ALTER TABLE DROP A FROM R (d) DELETE A FROM R 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. In MYSQL state the commands used to delete a row and a column respectively (a) DELETE,DROP (b) DROP,DELETE (c) DELETE,ALTER (d) ALTER,DROP Consider the following SQL statement. What type is this ? DROP TABLE items; (a) DML (b) DDL (c) DCL (d) TCL AGGREGATE FUNCTIONS Aggregate functions are example of __________? (a) Single row (b) Multi row (c) Both (a) & (b) (d) None of these How many types of Aggregate functions are available in SQL? (a) 2 (b) 3 (c) 5 (d) 6 Select the correct statement, with reference to SQL: (a) Aggregate functions ignore NULL (b) Aggregate functions consider NULL as zero or False (c) Aggregate functions treat NULL as a blank string (d) NULL can be written as 'NULL' also. Which of the following is a SQL aggregate function? (a) LEFT (b) AVG (c) JOIN (d) LEN Which of the following group functions ignore NULL values? (a) MAX (b) COUNT (c) SUM (d) All of the above Which of the following function is used to FIND the largest value from the given data in MYSQL? (a) MAX() (b) MAXIMUM() (c) LARGEST() (d) BIG() What values does the count(*) function ignore? (a) Repetitive values (b) Null values (c) Characters (d) None of the above If column “Salary” contains the data set {1000, 15000, 25000, 10000, 15000}, what will be theoutput after the execution of the given query? SELECT SUM(DISTINCT SALARY) FROM EMPLOYEE; (a)75000 (b) 25000 (c) 10000 (d) 50000 With SQL, how can you return the number of not null record in the Project field of “Students” table? a) SELECT COUNT (Project) FROM Students b) SELECT COLUMNS (Project) FROM Students c) SELECT COLUMNS (*) FROM Students d) SELECT COUNT (*) FROM Students 71. 72. 73. 74. 75. 76. 77. 78. Find the output of the MySQL query based on the given Table – COACH: Query: SELECT COUNT(GAME),AVG(SALARY) FROM COACH; (a) 3 70000 (b) 4 35000 (c) 4 70000 (d) 3 35000 Which of the following set of functions is a valid set of aggregated functions in MySQL? (a) AVG(),ROUND(),COUNT() (b) MIN(),UPPER(),AVG() (c) COUNT(),MAX(),SUM() (d) DATE(),COUNT(),LTRIM() Aggregate functions can be used in the select list or the _____ clause of a select statement. They cannot be used in a ______ clause. (a) Where, having (b) Having, where (c) Group by, having (d) Group by, where ORDER BY, GROUP BY , HAVING The SELECT statement when combined with clause, returns records in sorted order. (a) SORT (b) ARRANGE (c) ORDER BY (d) SEQUENCE Which of the following is correct sequence in a SELECT query? (a) SELECT,FRO,WHERE,GROUP BY, HAVING, ORDER BY (b) SELECT,WHERE,FROM,GROUP BY,HAVING,ORDER BY (c) SELECT,FROM,WHERE,HAVING,GROUP BY, ORDER BY (d) SELECT,FROM.WHERE,GROUP BY, ORDER BY, HAVING In MYSQL _____ clause applies the condition on every ROW and ______ clause applies the condition on every GROUP. If we have not specified ASC or DESC after a SQL ORDER BY clause, the following is used by default (a) DESC (b) ASC (c) There is no default value (d) None of the mentioned SQL applies conditions on the groups through ____ clause after groups have been formed. (a) Group by (b) With (c) Where (d) Having 79. For Given table "EMP" with following columns: Eno, Ename, Sal, Dept, Designation Select correct statement to display all records of "EMP" in descending order of Ename and within ascending order of Dept. (a) SELECT * FROM EMP ORDER BY ENAME,DEPT DESC; (b) SELECT * FROM EMP ORDER BY ENAME, ORDER BY DEPT DESC; (c) SELECT * FROM EMP ORDER BY ENAME DESC,DEPT; (d) SELECT * FROM EMP WHERE ORDER BY ENAME,DEPT DESC; 80. 81. 82. 83. Consider the following query Select * from employee order by salary ____, name _______ ; To display the salary from greater to smaller and name in alphabetical order which of the following option should be used? (a) ascending, descending (b) asc,desc (c) desc,asc (d) Descending,Ascending Which of the following will be the correct SQL command to add a new column FEES in a table TEACHER? (a) ALTER TABLE TEACHER ADD COLUMN FEES FLOAT; (b) ADD COLUMN FEES FLOAT INTO TEACHER; (c) UPDATE TEACHER ADD COLUMN FEES FLOAT; (d) INSERT INTO TEACHER ADD COLUMN FEES FLOAT; Find the output of the MySQL query based on the given Table – STUDENT SELECT SEC,AVG(MARKS) FROM STUDENT GROUP BY SEC HAVING MIN(MARKS)>80; (a) B 83 (b) A 84 (c) A 84 (d) A 83 B 83 B 80 Integers What is the meaning of “HAVING” clause in SELECT query? (a) To filter out the summary groups (b) To filter out the column groups (c) To filter out the row and column values (d) None of the above 84. 85. 86. 87. 88. Select correct SQL query from below to find the temperature in increasing order of all cites. (a) SELECT city FROM weather ORDER BY temperature; (b) SELECT city, temperature FROM weather; (c) SELECT city, temperature FROM weather ORDER BY temperature; (d) SELECT city, temperature FROM weather ORDER BY city; The HAVING clause does which of the following? (a) Acts EXACTLY like a where clause (b) Acts like a WHERE clause but is used for columns rather than groups. (c) Acts like a WHERE clause but is used for group rather than rows. (d) Acts like a WHERE clause but is used for rows rather than columns. Which SQL statement do we use to find out the total number of records present in the table ORDERS? (a) SELECT * FROM ORDERS; (b) SELECT COUNT (*) FROM ORDERS; (c) SELECT FIND (*) FROM ORDERS; (d) SELECT SUM () FROM ORDERS; JOINS Which join is equivalent to Cartesian Product? (a) INNER JOIN (b) OUTER JOIN (c) CROSS JOIN (d) NATURAL JOIN How many tables may be included with a join? (a) One (b) Two (c) Three (d) All of the Mentioned 89. (a) Outer Join (b) Inner Join (c) Self Join (d) Right Outer Join 90. 91. The following SQL is which type of Join? SELECT * FROM FACULTY,STUDENT; (a) Equi Join (b) Natural Join (c) Cartesian Product (d) Both (a) & (b) The following SQL command is which type of join: SELECT customer, cust_id,order,cust_id, name, order_id FROM customer, order; (a) Equi-join (b) Natural join (c) Outer join (d) Cartesian product 92. 93. 94. 95. Select the correct query/queries for cross join: (a)Select * FROM Table1 T1 NATURAL JOIN Table1 T2; (b)Select * FROM Table1 T1 ALL CROSS JOIN Table1 T2; (c)Select * FROM Table1 T1,Table1 T2; (d)Select * FROM Table1 T1 CROSS Table1 T2; Consider the following tables in a database Called SPORTS: Which is the best command from the following options to display the name of the player(PNAME) and their respective games(GNAME) (a) SELECT PNAME,G1D FROM PLAYERS; (b) SELECT PNAME,GNAME FROM GAMES,PLAYERS WHERE GAMES.G1D=PLAYERS.G1D; (c) SELECT PNAME,GNAME FROM GAMES,PLAYERS; (d) SELECT PNAME,GNAME FROM GAMES,PLAYERS WHERE P.G1D=G.G1D; The following SQL is which type of join? SELECT CUS_T. CUS_ID, ORDER_T. CUS_ID,NAME, ORDER_ID FROM CUS_T,ORDER_T WHERE CUS_T. CUS_ID = ORDER_T. CUS_ID; (a) Equi-join (b) Natural join (c) Outer join (d) Cartesian join Choose the correct option regarding the query: SELECT branch_name, COUNT (DISTINCT cust_name) FROM deposit, account WHERE deposit.acc_no = account.acc_no GROUP BY branch_id HAVING avg(bal) = 10000; (a) The having clause checks whether the query result is true or not (b) The having clause does not check for any condition (c) The having clause allows only those tuples that have average balance 10000. (d) None of the mentioned. ****************************************************** 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 2 MARKS Differentiate between DDL and DML. a. Give three examples of DDL & DML commands? b. What is the referential integrity constraint? Write the main difference between INSERT and UPDATE Commands in SQL. What is the similarity and difference between UNIQUE and PRIMARY KEY constraints? How is HAVING clause similar to WHERE clause? How is HAVING clause different from WHERE clause? Explain with the help of examples of each. What are aggregate functions in MySql? Give their names along with their use. Name the aggregate functions which work only with numeric data, and those that work with any type of data Differentiate between a Check and Default constraint in SQL with appropriate example. Give one difference between ROLLBACK and COMMIT commands used in MySql. What is the purpose of BETWEEN clause? Differentiate between equi join and cross join function in SQL with a example. Categorize the folowing commands as DML or TCL COMMIT ,UPDATE , DELETE ,SAVE POINT What is a not null constraint in SQL? Give example to illustrate. Differentiate between DROP and DELETE commands in SQL with appropriate example. What is the use of order by clause in SQL? Give example. What is the difference between Equi join and Natural join? Give an Example. (a)What is the difference between column constraint and table constraint? Give an example. (b) What is the difference between LIKE and IN operator in MYSQL. Give an example. (a)Differentiate between ALTER and UPDATE commands in SQL. (b) In the following query how many rows will be deleted? DELETE Student WHERE StudentID=105; (Assuming a Student table with primary key StudentID) (a) Differentiate ORDER BY and GROUP BY with an example. (b) Classify the following statements into DDL and DML a) delete b) drop table c) update d) create table 20. 21. 22. 23. 24. 25. 1. What is the difference between CHAR and VARCHAR? Write 2-3 differences. What is the difference between WHERE and HAVING Clause? Can we use them together in a query? Which command is used to remove UNIQUE KEY constraint from an existing table? Consider the following two commands with reference to a table, named Students, having a column named Section: (a) SELECT COUNT(SECTION) FROM STUDENTS; (b) SELECT COUNT(*) FROM STUDENTS; If these two commands are producing different results, (i) What may be the possible reason? (ii) Which command, (a) or (b), might be giving higher value? Define Cartesian Product with an example. Write the difference between the following SQL Queries: (i) ALTER TABLE EMP DROP AGE; (ii) DROP TABLE EMP; 2 MARKS (OR) 3 MARKS (OR) 4 MARKS Write the output of the queries (i) to (iv) based on the table, TECH_COURSE given below: (i) SELECT DISTINCT TID FROM TECH_COURSE; (ii) SELECT TID, TECH_COURSE COUNT(*), GROUP MIN(FEES) BY TID FROM HAVING COUNT(TID)>1; (iii) SELECT CNAME FROM TECH_COURSE WHERE FEES>15000 ORDER BY CNAME; (iv) SELECT AVG(FEES) FROM TECH_COURSE WHERE FEES BETWEEN 15000 AND 17000; 2. 3. Write the outputs of the SQL queries (i) to (iv) based on the relations Teacher and Placement given below: (i) SELECT Department, avg(salary) FROM Teacher GROUP BY Department; (ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher; (iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department = P.Department AND Salary>20000; (iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender =‟F‟ AND T.Department=P.Department; Write the output of the queries (a) to (d) based on the table, Furniture given below: (a) SELECT SUM(DISCOUNT) FROM FURNITURE WHERE COST>15000; (b) SELECT MAX(DATEOFPURCHASE) FROM FURNITURE; (c) SELECT * FROM FURNITURE WHERE DISCOUNT>5 AND FID LIKE "T%"; (d) SELECT DATEOFPURCHASE FROM FURNITURE WHERE NAME IN ("Dining Table", "Console Table"); 4. 5. Write queries (a) to (d) based on the tables EMPLOYEE and DEPARTMENT given below: (a) To display the average salary of all employees, department wise. (b) To display name and respective department name of each employee whose salary is more than 50000. (c) To display the names of employees whose salary is not known, in alphabetical order. (d) To display DEPTID from the table EMPLOYEE without repetition. Consider the following two tables: What will be the degree and cardinality of the Cartesian product and the Natural join of these tables? 6. 7. Write the SQL Queries for (i) to (iii) based on the table EMPLOYEE and DEPARTMENT. (i) To display department name and number of employees in each department where no of employees is greater than one. (ii) To display department name and sum of the salary spent by the department, where the total amount spent by the department as salary is more than 100000. (iii) To display the name of the employee in descending order of their seniority. Write the outputs of the SQL queries (i) to (iv) based on the relationsTeacher and Placement given below: (i) SELECT Department, max(salary) FROM Teacher GROUP BY Department; (ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM 8. Teacher; (iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department = P.Department AND P.Department='History'; (iv) SELECT Name, Place FROM Teacher natural join Placement where Gender='F'; (a) Consider the following table structure: Write a SQL query to remove unique constraints from the table. (b) Consider the following table: 9. (i) SELECT SNAME,STREAM FROM XII_A HAVING STREAM LIKE '%B%'; (ii) SELECT STREAM, COUNT(*) FROM XII_A GROUP BY STREAM HAVING COUNT(STREAM)<=1; (iii) SELECT AGE, STREAM FROM XII_A WHERE AGE BETWEEN 15 AND 15 ORDER BY SNAME; (iv) SELECT ROLLNO, STREAM FROM XII_A WHERE STREAM LIKE "P%B" AND STREAM <>"BS"; HARSH AGARWAL has created a table named 'Actor' which contains a field called Aname. Write MySQL queries for the followings: (i) To show all the names of the actors which contain the string 'ch' in it. (ii) To display all the names of the actors which contain exactly 5 characters andalso the second characters is 'o' (such as Gopal or Mohan). 10. Consider the following tables FACULTY and STUDENT. Write the output for the MYSQL statement given below and state what type of join is implemented. SELECT * FROM FACULTY,STUDENT 11. Write SQL queries for (i) to (iv) 12. (i) Display the Trainer Name, City & Salary in descending order of their Hiredate. (ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of December 2001. (iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and COURSE of all those courses whose FEES is less than or equal to 10000. (iv) To display number of Trainers from each city. Using the above Question‟s table Trainer and Course Write the output for the following SQL Queries: (i) SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT IN(„DELHI‟, „MUMBAI‟); (ii) SELECT DISTINCT TID FROM COURSE; (iii) SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY TID HAVING COUNT(*)>1; (iv) SELECT COUNT(*), SUM(FEES) FROM COURSE WHERE STARTDATE< „2018-09-15‟; 13. Consider the following tables GAMES. Give outputs for SQL queries (i) to (iv). Table : GAMES (i) SELECTCOUNT(DISTINCTNumber)FROMGAMES; (ii) SELECT MAX(ScheduleDate), MIN(ScheduleDate) FROM GAMES; (iii) SELECT SUM(PrizeMoney) FROM GAMES; (iv) SELECT * FROM GAMES WHERE PrizeMoney>12000; 14. Write the output of the queries (i) to (vi) based on the table given below: (i) Select BRAND_NAME, FLAVOUR from CHIPS where PRICE <> 10; (ii) Select * from CHIPS where FLAVOUR=”TOMATO” and PRICE > 20; (iii) Select BRAND_NAME from CHIPS where price > 15 and QUANTITY < 15; (iv) Select count( distinct (BRAND_NAME)) from CHIPS; (v) Select price , price *1.5 from CHIPS where FLAVOUR = "PUDINA"; (vi) Select distinct (BRAND_NAME) from CHIPS order by BRAND_NAME desc; 15. 16. Write SQL statements for the q.no (i) to (iv) and output for (v) Write the SQL commands for the following : (i) To show firstname,lastname,address and city of all employees living in paris (ii) To display the content of Employees table in descending order of Firstname. (iii) To display the firstname,lastname and total salary of all managers from the tablesEmployee and empsalary , where total salary is calculated as salary+benefits. (iv) To display the maximum salary among managers and clerks from the table Empsalary. (v) To display the average salary of Clerk. (i) Write a Query to insert House_Name=Tulip, House_Captain= Rajesh andHouse_Point=278 into table House(House_Name, House_Captain, House_Points) (ii) Write the output for SQL queries (i) to (iv), which are based on the table: STUDENTgiven below: 17. (i) SELECT COUNT(*), City FROM STUDENT GROUP BY CITY HAVING COUNT(*)>1; (ii) SELECT MAX(DOB),MIN(DOB) FROM STUDENT; (iii) SELECT NAME,GENDER FROM STUDENT WHERE CITY="Delhi"; (iv) SELECT DISTINCT Class FROM STUDENT; Write the outputs of the SQL queries (i) to (iv) based on the relations student and sports given below: (i) SELECT ROLL_NO,AGE,GNAME FROM STUDENT ST, SPORTS SP WHERE ST.ROLL_NO=SP.ROLL_NO AND GNAME LIKE „_R%‟; (ii) SELECT AGE,GENDER FROM STUDENT WHERE DOB IS NOT NULL AND AGE>15; (iii) SELECT SNAME,GENDER FROM STUDENT WHERE AGE NOT IN(12,22); (iv) SELECT GENDER,AVG(TOTAL) FROM STUDENT WHERE GENDER IN(„M‟,‟F‟) GROUP BY GENDER; 18. 19. (i) Display the SurNames, FirstNames and Cities of people residing in Udhamwara city. (ii) Display the Person Ids (PID), cities and Pincodes of persons in descending order of Pincodes. (iii) Display the First Names and cities of all the females getting Basic salaries above 40000. (iv) Display First Names and Basic Salaries of all the persons whose firstnames starts with "G". Write the output for the queries (i) to (iv) based on the table given below: (i) SELECT MAX(FEES),MIN(FEES) FROM SPORTS; (ii) SELECT COUNT(DISTINCT SNAME) FROM SPORTS; (iii) SELECT SNAME,SUM(No_of_Players) FROM SPORTS GROUP BY SNAME; (iv) SELECT AVG(FEES*No_of_Players) FROM SPORTS WHERE SNAME=”Basket Ball”; 20. Consider the following tables DOCTOR and SALARY. Write SQL commands for the following statements. (i) Display NAME of all doctors who are in "ORTHOPEDIC" having more than 10 years experience from the table DOCTOR. (ii) Display the average salary of all doctors working in "ENT" department using the DOCTOR and SALARY. (Salary= Basic + Allowance) (iii) Display the minimum ALLOWANCE of female doctors. (iv) Display the highest consultation fee amount for all male doctors. ********************************************************