0% found this document useful (0 votes)
424 views35 pages

SQ L Worksheet 24

Uploaded by

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

SQ L Worksheet 24

Uploaded by

Purnima E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

CHAPTER 7 – INTRODUCTION TO SQL AND ITS CONCEPTS

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.

11. Write the appropriate operator for the following situation


with its syntax:
(i) To select range of values.
(ii) To Perform Pattern Matching.
(ii) To select partially known string or phrase from a table.
(iii) To select Unknown Record(s) from a SQL table.
12. Differentiate between the following with an example.
(i) IN vs BETWEEN (ii) OR vs IN operator (ii) == vs LIKE
(iii) Wildcards: % (percentage) vs _ (Underscore)
(iv) UPDATE vs ALTER (v) DELETE vs DROP
13. Write the difference between the following SQL Queries:
(i) ALTER TABLE EMP DROP AGE;
(ii) DROP TABLE EMP;
14. Categorize the following commands as DML or TCL:
COMMIT, UPDATE, DELETE, SAVE POINT
15. Give one difference between ROLLBACK and COMMIT
commands used in MySql.
16. Define aggregate functions. List out its types.
17. In SQL, write the name of the aggregate function which
will display the cardinality of a table.
18. Consider the following two commands with reference to a
table, named Employee having a column named Department.

(a) SELECT COUNT(DEPT) FROM EMPLOYEE;


(b) SELECT COUNT(*) FROM EMPLOYEE;
If these two commands are producing different results,
(i) What may be the possible reason?
(ii) Which command (a) or (b) might be giving a higher value?
19. Differentiate between the following with an example:
(i) Order By Clause vs Group By Clause
(ii) Where Clause vs Having Clause.
20. Neelam, a database administrator needs to display Class wise
total number of students of ‘XI’ and ‘XII’ house. She is encountering
an error while executing the following query:
SELECT CLASS, COUNT (*) FROM STUDENT ORDER BY
CLASS HAVING CLASS=’XI’ OR CLASS= ‘XII’;
Help her in identifying the reason of the error and write
the correct query by suggesting the possible correction (s).
21. Mr. Rehan, a database administrator wants to display
highest salary in each department from table Employee
with columns Ecode, Ename, Salary, Gender, Dept. He is
encountering an error while executing the following query:
SELECT DEPT, MAX(SALARY) FROM EMPLOYEE;
Help her in identifying the reason of the error and write the
correct query by suggesting the possible correction (s).
22. Ram wants to count number of staffs under each category where
the number of staffs is more than 2. He has executed the following
query:

SELECT CATEGORY, SUM(SALARY) FROM HOTEL WHERE


COUNT(*)>2 GROUP BY CATEGORY;
But he got an error. Identify the error(s) and rewrite the query.
Also underline the correction(s) done.
22. What is meant by Joins? List out the various types of joins
in SQL.
23. Define Cartesian product with an example.
24. Write the difference between:
(i) Equi- Join and Cross Join.
(ii) Equi-Join and Natural Join.
STATE TRUE OR FALSE
1. SQL is a programming language.
2. Unique is used to eliminate the duplicate rows from the output in
SQL query.
3. Delete command deletes the table structure and Drop command
deletes the data from a SQL Table .
4. Null (unavailable and unknown) values are entered by the
following command:
5. INSERT INTO TABLE_NAME VALUES (“NULL”);
6. Foreign key column derives its value from the primary key of the
parent table.
7. ALTER TABLE command is used to modify the structure of the
table.
8. DML commands are used to define a database, including
creating, altering, and dropping tables and establishing
constraints.
9. Unique and Primary key constraints are the same.
10. NOT NULL is a constraint that can be defined only at the column
level.
11. DDL is similar to a computer programming language for defining
data structures, especially database schemas.
12. The condition in a WHERE clause in a SELECT query can refer to
only one value.
13. The rows of the result relation produced by a SELECT statement
can be sorted but only by one column.
14. The WHERE clause is used to specify filtering conditions for
groups.
15. The SQL statement: SELECT salary + Comm AS Total FROM Emp;
adds two fields salary and comm from each row together and lists
there results in a column named Total.
16. The BETWEEN operator includes both begin and end values.
17. Logical operators and Relational operators cannot be used together.
18. Update and delete statements are DDL statements.
19. When multiple operators are used in a SQL Query, low precedence
operators are evaluated in last.
20. A user may specify two or more columns as using the SELECT –
DISTINCT clause
21. MIN and MAX can only be used with numeric columns.
22. The SQL keyword GROUP BY instructs the DBMS to group together
those rows that have the same value in a column
23. SUM () function is used to count the total number of records in a
table
24. COUNT () function ignores null values while counting the records.
25. COUNT(*) function ignore duplicates and null values while counting
the records.
26. MAX() function returns an integer field.
27. You can combine all the records that have identical values in a
particular field on a group of fields by using ORDER BY statement.
28. To filter the conditions for groups, WHERE clause is used.
29. Group functions can be applied on any data typesi.e numeric, data,
string.
30. Any attribute which is present in the having clause without being
aggregated must not be present in the group by clause.
31. We can rename the resulting attribute after the aggregation
function has been applied.
32. To avoid a Cartesian product, always include a valid join condition
in a WHERE clause.
33. Understanding the primary and foreign key relationship is not
important to join on the correct columns.
34. COUNT(Fieldname) tallies only those rows that contain a value; it
ignores all null values.
ASSERTION & REASONING
1. A: A Primary Key is used to uniquely identify a
record in a relation.
R: A Primary Key cannot have duplicate value.
2. A: Single row functions work with a single row.
R: A single row function returns aggregated value.
3. A: All the candidate keys are Primary Key.
R: Primary Key is used to uniquely identify a record in a
relation.
4. A: Foreign Key is not used to uniquely identify a record in
relation.
R: Foreign key can take NULL values
5. A: NULL is Special value that is stored when actual data
value is unknown for an attribute.
R: Foreign key can take NULL values
6. A: Each attribute in a relation has a unique name.
R: Sequence of attributes in a relation is immaterial.
7.

A: Select Avg(charges) from Hospital; Output: 166.666667


R: Avg() includes NULL values.
8. A: A unique key cannot serve the purpose of a
Primary Key
R: A unique key attribute can hold null value
9. A: Update is a DDL command.
R: DDL commands are used for defining the schema of the
database.
10. A: Create cs database;
R: Create database database_name help us to create
database.
11. A: Delete is DML command
R: Delete command deletes the table from a database
12. A: Float datatype cannot be used for storing names
R: Char(n) datatype can be used for storing names
13. A: Drop is not a DML command
R: Drop is a TCL command
14. 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.
15. A: Suppose there are suppliers from 30 different cities.
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.
16. 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.
17. A: ALTER TABLE table_name ADD column_name datatype.
R: Alter table help us to modify the data values of a
given table.
18. A: DELETE FROM relation_name WHERE condition.
R: DELETE is a DML command and used when we want to
remove some or all the tuples from a relation.
19. 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
20. A: All candidate keys can be used as a primary
key.
R: We can use more than one candidate key as
a primary key.
21. 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.
22. A: The keyword DISTINCT is used with SELECT command.
R: DISTINCT keyword eliminates duplicate rows
23. 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 two
tables will be the product of the cardinalities of these two
tables.
R: Cartesian product generates all possible combination of two
tables
25. A: Count(*) and Count(Column Name) returns same
outputs.
R: Null values are not counted by Count()
26. A: Select Dept, count (*) from hospital group by Dept where
count (*)>1; Output: Error
R: Exactly one patient admitted in each Dept.
27. A: Select Max (Name) from hospital; Output: Error
R: Max( ) can only be used with numeric columns
28. 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
29. 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.
30. 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.
31. 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.
32. 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…
OBJECTIVE TYPE QUESTIONS (MCQ)
1. A relational database consists of a collection of
(a) Tables (b) Fields (c) Records (d) Keys
2. 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
3. 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
4. key is used to join two relations in RDBMS?
(a)Primary Key (b) Candidate Key
(c) Foreign Key (d)Unique Key
5. 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
6. The term is used to refer to a record in a table.
(a) Attribute (b) Tuple (c) Field (d) Instance
7. Which of the following will remove the primary key from MySQL
table?
(a) remove (b) alter (c) drop (d) update
8. A/An in a table represents a logical relationship
among a set ofvalues.
(A) Attribute (B) Key (C) Tuple (D) Entry
9. The term is used to refer to a record in a table.
(A) Attribute(B) Tuple(C) Field(D) Instance
10. Which of the following attributes cannot be considered as a choice
for primarykey?
(a) Id(b) License Number(c) Dept_Id(d) Street
11. 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
12. The term is used to refer to a field in a table.
(a)Attribute (b) Tuple (c) Row (d)Instance
13. 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. 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
15. 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.
16. 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
17. ....................... Command helps to fetch data from relation.
(a)Use (b) Show (c) Fetch (d)Select
18. ............................. Command helps to open the database for use.
(a)Use (b) Open (c) Distinct (d)Select
19. 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
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

94. 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)
95. 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
96. 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;
97. Consider the following tables in a database Called SPORTS:
Which is the best command from the following options to
display the name of the PNAME and their respective 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;
98. 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
99. 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.
3 MARKS (OR) 4 MARKS
1. Rashmi has forgotten the names of the databases, tables and the
structure of the tables that she had created in Relational Database
Management System (RDBMS) on her computer.
(a) Write the SQL statement to display the names of all the
databases present in RDBMS application on her
computer.
(b) Write the statement which she should execute to open
the database named "STOCK".
(c) Write the statement which she should execute to
display the structure of the table "ITEMS" existing in the
above opened database "STOCK".
2. Consider the table HOTEL given below and write any four SQL
commands :
Table : HOTEL

(i) Display the details of all the Hotels situated in London.


(ii) Display the details of all 'Deluxe' rooms with price
more than 6000 in ascending order of Price.
(iii) Display the Hotel names that end with ''e''.
(iv) Count different types of rooms available in the Hotels.
(v) Display the Hotel names in descending order.
3. Write SQL statements for the following queries (i) to (v) based
on the relations CUSTOMER and TRANSACTION given below :
(a) To display all information about the CUSTOMERs whose
NAME starts with 'A'.
(b) To display the NAME and BALANCE of Female CUSTOMERs
(with GENDER as 'F') whose
TRANSACTION Date (TDATE) is in the year 2019.
(c) To display the total number of CUSTOMERs for each GENDER.
(d) (i) To display the CUSTOMER NAME and BALANCE in
ascending order of GENDER.
(ii) To display CUSTOMER NAME and their respective
INTEREST for all CUSTOMERs where INTEREST is
calculated as 8% of BALANCE.

4. (a) Ram wants to find the sum of commission earned by


each department. He has executed the following query :
SELECT dept,sum(comm) GROUP BY dept
FROM EMP;
But, he got an error. Rewrite the correct query after
identifying the error(s).
(b) Consider the following Table : ITEM

Find the output of the following SQL queries :


(a) SELECT 10+ QTY FROM ITEM WHERE ID = "P1003";
(b) SELECT PRICE*QTY FROM ITEM WHERE QTY < 2;
5. Consider the Table FURNITURE with the following data:

Write SQL queries for the following :


(a) To Display all the records in descending order of Item.
(b) To Display the Type and total number of items of each
Type.
(c) To Display the highest Price.
(d) To Display the Item with their price rounded to 1
decimal place.
6. 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, 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:

(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;
8. 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");
9. 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.
10. Consider the following tables– EMPLOYEES AND DEPARTMENT:
What will be the output of the
following statement?

SELECT ENAME, DNAME


FROM EMPLOYEES E,
DEPARTMENT D WHERE
E.DNO=D.DNO;

11. Write the output of SQL queries (a) and (b) based on the follwing two
tables DOCTOR and PATIENT belonging to the same database:

(a) SELECT DNAME,PNAME FROM DOCTOR NATURAL


JOIN PATIENT;
(b) SELECT PNAME, ADMDATE, FEES FROM PATIENT P,
DOCTOR D WHERE D.DNO=P.DNO AND FEES>1000;
12. Consider the following two tables:

What will be the degree and


cardinality of the Cartesian
product and the Natural join of
these tables?

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

14. 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 and also the second characters is 'o' (such as
Gopal or Mohan).
15. Consider the following tables –
LOAN and BORROWER:

How many rows and columns


will be there in the natural join
of these two tables?
16. Consider the following tables MUSIC and DANCE:

Identify the degree and cardinality of:


a) Union operation on MUSIC and DANCE.
b) Intersection operation on MUSIC and DANCE.
17. Consider the SQL table "PRODUCT_SALES" with the following
data:

Predict the output of the following queries based on the table


"PRODUCT_SALES" given above:
1. SELECT (SalesQ2 - SalesQ1) / 2 AS Sale2 FROM
PRODUCT_SALES WHERE Segment = 'High';
2. SELECT SUM(SalesQ1) AS "TOTAL” FROM
PRODUCT_SALES WHERE Region = 'B';
18. (a) Consider the table, BOOK and MEMBER given below:

What will be the output of the following statement?


SELECT * FROM BOOK NATURAL JOIN MEMBER;
(b) Write the output of the queries (i) to (iv) based on
the table.
Table: Employee

i SELECT NAME, PROJECT FROM EMPLOYEE ORDER


BY NAME DESC;
ii SELECT NAME, SALARY FROM EMPLOYEE WHERE
NAME LIKE 'A%';

iii SELECT NAME, DOJ FROM EMPLOYEE WHERE


SALARY BETWEEN 100000 AND 200000;
iv SELECT * FROM EMPLOYEE WHERE PROJECT = 'P01';
19. Write SQL Queries for (a) to (d) based on the tables
PASSENGER and FLIGHT
given below:

(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) 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.
21. Write the outputs of the SQL queries

(i) SELECT DEPARTMENT, MAX(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 P.DEPARTMENT='HISTORY';
(iv) SELECT NAME, PLACE FROM TEACHER NATURAL JOIN
PLACEMENT WHERE GENDER='F';
22. (a) Consider the following table structure:

Write a SQL query to remove unique constraints from the table.

(b) Consider the following table:

(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";
23. Write the output (i-iii) for the following SQL commands

(i) SELECT MAX(DOB) FROM PARTICIPANTS;


(ii) SELECT DISTINCT EVENT FROM PARTICIPANTS;
(iii) SELECT COUNT(DISTINCT(CLASS)) FROM PARTICIPANTS;
(iv) SELECT MAX(DOB), PNO FROM PARTICIPANTS GROUP BY
PNO HAVING COUNT(*)>1
24. Using the table of Q.No 25 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’;
25. 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;
26. 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.
27. (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:

(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;
28. 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;
29.

(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".
30. 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”;
31. Consider the following tables 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.

**********************************************************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy