SQ L Worksheet 24
SQ L Worksheet 24
PRACTICE QUESTIONS
THEORY QUESTIONS
1. Define SQL.
2. Write the difference between Single row functions and multi
row functions with an example.
3. What is the referential integrity constraint?
4. List out Various commands available under DDL and DML.
5. Write the appropriate command for the following situations:
(i) To Show the structure of the table.
(ii) To Create table/database.
(iii) To List out an existing database name.
(iv) To open an existing database.
(v) To List out existing table name.
6. Define Constraints. List out its types.
7. Differentiate the following with an example:
(i) DBMS vs RDBMS (ii) DDL vs DML (iii) Char vs Varchar
(iv) Primary key vs Unique (v) Primary key vs foreign key
(vi) Default vs NOT NULL
8. Write the appropriate command for the following situation:
(i) To delete structure of the table.
(ii) To add a new attribute in a table.
(iii) To Eliminates redundant data from a Query Result.
(iv) To display the records in ascending order of an attribute.
(v) To modify the structure of the table.
(vi) To delete records of the table.
(vii) To modify the structure of the table.
(viii) To add primary key in an existing table.
9. Categorize following commands into DDL and DML commands:
INSERT INTO, DROP TABLE, ALTER TABLE, UPDATE, SELECT
10. Raj needs to display names of students, who have not been Assigned
any stream or have been assigned Course_name that ends with
"Economics". He wrote the following command, which did not
give the desired result.
SELECT Name, Class FROM Students WHREE
Course_name=Null OR Course_name="%Economics";
Help him to run the query by removing the error and write
the correct query.
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
20. 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
21. Which of the following data type will be the best choice for storing
price of anytime?
(a) string (b) int (c) date (d) float
22. Which is not a constraint in SQL?
(a)Unique (b) Distinct (c) Primary key (d) Check
23. The term "SQL" stands for
(a) Standard query language
(b) Sequential query language
(c) Structured query language
(d) Server-side query language
24. 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
25. Which of the following is NOT a DML command?
(a) SELECT (b) DELETE (c) UPDATE (d) DROP
26. 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
27. Which of the following is/are the DDL statements?
(a) Create (b) Drop (c) Alter (d) All of these
28. 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;
29. 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;
30. 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>
31. 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;
32. 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
33. 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. Which command shows the table structure of table emp?
(a) Select * from emp; (b) Show all from emp;
(c) Desc emp; (d) Des emp;
35. 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) 6,20 (c) 9,6 (d) 6,9
36. The SQL keyword(s) is used with wildcards.
(a) LIKE only (b) IN only
(c) NOT IN only (d) IN and NOT IN
37. 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 DISTINCT(MARKS) FROM STUDENTS;
(a) 25, 35, 25, 35, 38 (b) 25, 25, 35, 35
(c) 25, 35, 38 (d) 25, 25, 35, 35
38. 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
39. 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
40. Which of the following is not a SQL Logical Operator?
(a) = (b) and (c) or (d) not
41. 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
42. 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. 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);
44. 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
45. 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
46. (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.
47. 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;
48. Consider the following SQL statement. What type of statement is
this? SELECT * FROM Employee ;
(a) DML (b) DDL (c) DCL (d) Integrity Constraint
49. 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
50. 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
51. 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. 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*0.1;
(b) UPDATE STUDENT SET FEES=FEES*0.1;
(c) UPDATE STUDENT SET FEES=FEES*10%;
(d) UPDATE STUDENT SET FEES 10%;
53. 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
54. 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
55. command is used to add a new column in a table in SQL.
(a) update (b) remove (c) alter (d)drop
56. 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
57. What does the following query do?
UPDATE EMPLOYEE SET SAL=SAL-(SAL * 1.10);
(a) It increases the salary of all the employees by 10%
(b) It decreases the salary of all the employees by 110%
(c) It increases the salary of all the employees by 110%
(d) It is syntactically incorrect.
58. 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
59. 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. 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
61. Consider the following SQL statement. What type is this ?
DROP TABLE items;
(a) DML (b) DDL (c) DCL (d) TCL
AGGREGATE FUNCTIONS
62. Aggregate functions are example of ?
(a) Single row (b) Multi row
(c) Both (a) & (b) (d) None of these
63. How many types of Aggregate functions are available in SQL?
(a) 2 (b) 3 (c) 5 (d) 6
64. If column “AGE” of table STUDENT contains the data set (20, 50,
43, 12, 73), what will be the output after execution of the following
query.
SELECT MAX(AGE) – MIN(AGE) FROM STUDENT;
(a) 30 (b) 7 (c) 61 (d) 30
65. 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.
66. Which of the following is a SQL aggregate function?
(a) LEFT (b) AVG (c) JOIN (d) LEN
67. Which of the following group functions ignore NULL values?
(a) MAX (b) COUNT (c) SUM (d) All of the above
68. 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()
69. Which type of values will not considered by SQL while executing
the following statement?
SELECT COUNT(column_name) FROM INVENTORY;
a) Numeric value b) Text value c) Null value d) Date value
70. What values does the count(*) function ignore?
(a) Repetitive values (b) Null values
(c) Characters (d) None of the above
71. In column "Margin"contains the data set
(2.00,2.00,NULL,4.00,NULL,3.00,3.00)
what will be the output of after the execution of the given query?
SELECT AVG(Margin) FROM SHOP;
(a) 2.9 (b) 2.8 (c)2.00 (d) All of these
72. Consider the following table Cosmetics.
What will be the output after the execution of the given query?
SELECT COUNT (DISTINCT NAME) FROM COSMETICS ;
(a) 5 (b) 6 (c) 4 (d) 2
73. If column “Salary” contains the data set {1000, 15000, 25000,
10000, 15000}, what will be the output after the execution of
the given query?
SELECT SUM(DISTINCT SALARY) FROM EMPLOYEE;
(a)75000 (b) 25000 (c) 10000 (d) 51000
74. 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
75. 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
76. 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()
77. 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
78. The SELECT statement when combined with clause, returns
records in sorted order.
(a) SORT (b) ARRANGE (c) ORDER BY (d) SEQUENCE
79. Which of the following is correct sequence in a SELECT query?
(a) SELECT,FROM,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
80. In MYSQL clause applies the condition on every ROW and
clause applies the condition on every GROUP.
81. 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
82. SQL applies conditions on the groups through clause after
groups have been formed.
(a) Group by (b) With (c) Where (d) Having
83. 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
NAME,DEPT DESC;
84. 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
85. 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;
86. 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
87. 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
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;
89. 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.
90. 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
91. Which join is equivalent to Cartesian Product?
(a) INNER JOIN (b) OUTER JOIN
(c) CROSS JOIN (d) NATURAL JOIN
92. How many tables may be included with a join?
(a) One (b) Two (c) Three (d) All of the Mentioned
93.
(a) Outer Join
(b) Inner Join
(c) Self Join
(d) Right Outer Join
(i) SELECT
DISTINCT TID FROM TECH_COURSE;
(ii) SELECT TID, COUNT(*), MIN(FEES) FROM TECH_COURSE
GROUP BY TID 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;
7. Write the outputs of the SQL queries (i) to (iv) based on the
relations Teacher and Placement given below:
11. Write the output of SQL queries (a) and (b) based on the follwing two
tables DOCTOR and PATIENT belonging to the same database:
13. 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
(a) Write a query to change the fare to 6000 of the flight whose
FNO is F104.
(b) Write a query to display the total number of MALE and
FEMALE passengers.
(c) Write a query to display the NAME, corresponding FARE and
F_DATE of all passengers who have to START from DELHI.
(d) Write a query to delete the records of flights which end at end
MUMBAI.
20. Write the SQL Queries for the following tables:
‘
(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;
26. Write SQL statements for the q.no (i) to (iv) and output for (v)
**********************************************************