SQL Command Quiz Questions
SQL Command Quiz Questions
2 Which of the following commands will remove the entire database from MYSQL?
(A) DELETE DATABASE (B) DROP DATABASE
(C) REMOVE DATABASE (D) ALTER DATABASE
5 Which function is used to display the total number of records from a table in a database?
(A) total() (B) total(*) (C) return(*) (D) count(*)
14 All tuples in the relation are assigned NULL as the value for the new Attribute,with the
________Command
(a) MODIFY (b) TAILOR (c)ELIMINATE (d) ALTER
16 Which of the following is not a legal method for fetching records from a database from
within a Python program?
(a) fetchone() b)fetchtwo() (c) fetchall() (d) fetchmany()
18 An attribute in a relation is a foreign key if it is the ________ key in any other relation.
(a) Primary Key (b) Foreign Key (c) Candidate Key (d) Unique Key_
19 When two conditions must both be true for the rows to be selected, the conditions are
separated by the SQL keyword
(a)ALL (b) IN (c) AND (d)OR
20 The statement which is used to get the number of rows fetched by execute( ) method of
cursor:
(a) [Link]( ) (b) [Link]()
(c) [Link]( ) (d) [Link]( )
23 _________ is a non-key attribute, whose values are derived from the primary key of
some other table.
(a) Foreign Key (b) Primary Key (c) Candidate Key (d) Alternate Key
25 Which function is used to display the total number of records from a table in a
database?
(a) sum(*) (b) total(*) (c) count(*) (d) return(*)
26 Which of the following function is used to established connection between Python and
MySQL database?
(a) connection() (b) connect() (c) Connect() (d) None
27 ____________command is used to delete the table from the database of SQL.
(a) update (b)remove (c) alter (d) drop
28 Which of the following commands will use to change the structure of table in
MYSQL database?
(a)DELETE TABLE (b)DROP TABLE
(c)REMOVE TABLE (d)ALTER TABLE
29 __________is an attribute whose value is derived from the primary key of some other
table.
(a) Primary Key (b) Foreign Key (c) Candidate Key (d) Alternate Key
32 To establish a connection between Python and SQL database, connect() is used. Which of
the following value can be given to the keyword argument –host, while calling connect ()?
(a) localhost (b) [Link] (c) any one of (a) or (b) (d) localmachine
38 Which of the following commands will delete a table from a MYSQL database?
a) DELETE b) DROP c) REMOVE d) ALTER
44 Which of the following SQL statements is used to open a database named “SCHOOL”?
a) CREATE DATABASE SCHOOL; (b) USE DATABASE SCHOOL;
(c) USE SCHOOL; (d) SHOW DATABASE SCHOOL;
45 A relation can have only one______key and one or more than one______keys.
(a) PRIMARY, CANDIDATE (b) CANDIDATE, ALTERNATE
(c )CANDIDATE ,PRIMARY (d) ALTERNATE, CANDIDATE
46 What are the minimum number of attributes required to create a table in MySQL?
(a) 1 (b) 2 (c) 0 (d)3
48 What are the mandatory arguments which are required to connect a MySQL database to
python?
(a) username, password, hostname, database name
(b) username, password, hostname
(c) username, password, hostname, port
(d) username, password, hostname, table name
49 Identify the SQL query which is expected to delete all rows of a table emp without deleting
its structure and write the correct one:
(a) DELETE TABLE emp; (b) DROP TABLE emp;
(c) REMOVE TABLE emp; (d) DELETE FROM emp;
50 All attribute combinations inside a relation that can serve as primary key are ________
(a) Primary Key b) Foreign Key (c) Candidate Key (d) Alternate Key
52 All aggregate functions except _______ ignore null values in their input collection.
(a) Count (attribute) (b) Count (*) (c) Avg (d) Sum
53 A database ___________is a special control structure that facilitates the row by row
processing of records in the result set.
(a) Fetch (b) table (c) cursor (d) query
54 The ________ command is used in a WHERE clause to search for a specified pattern in a
column.
(a) match (b) similar (c) like (d) pattern
56 For each attribute of a relation, there is a set of permitted values, called the _______of
that attribute.
(a) cardinality (b) degree (c) domain (d) tuple
57 The SELECT statement when combined with __________ clause, returns records in
sorted order.
(a) SORT (b) ARRANGE (c) ORDER BY (d) SEQUENCE
58 In SQL, the aggregate function used to calculate and display the average of numeric values
in an attribute of a relation is:
(a) sum() (b) total() (c) count() (d) avg()
59 The name of the module used to establish a connection between Python and SQL database
is-
(a) mysql-connect (b) mysql-connector (c) mysql-interface (d) mysql-conn
60 __ command is used to a remove a tuple or many tuple(s) from a table / relation in SQL
(a) drop (b)delete (c) remove (d) alter
61 Which of the following commands will remove a particular table’s schema along with its
data, contained in a MySQL database?
a. DROP DATABASE b. ALTER TABLE c. DELETE FROM TABLE d. DROP TABLE
62 ........................is an attribute, which is not a primary key of a table but has a capability of
becoming a primary key.
a. Primary Key b. Foreign Key c. Candidate Key d. Alternate Key
63 To restrict repeated values from being entered under a column of table, while creating the
table in MySQL we take help of which of the following :
a. DESCRIBE b. NULL c. PRIMARY KEY d. DISTINCT
65 Which of the following method is needed to create an object using whose method a query
is executed from python’s front end connected to a mysql database.
a. cursor( ) b. execute( ) c. Connect( ) d. fetchall( )
66 A table has initially 5 columns and 8 rows. Consider the following sequence of operations
performed on the table –
i. 8 rows are added ii. 2 columns are added
iii. 3 rows are deleted iv. 1 column is added
What will be the cardinality and degree of the table at the end of above operations?
(a) 13,8 (b) 8, 13 (c) 14,5 (d) 5,8
69 Which of the following clause is used to remove the duplicating rows from a select
statement?
(a) or (b) distinct (c) any (d)unique
70 Which of the following method is used to create a connection between the MySQL
database and Python?
(a) connector ( ) (b) connect ( ) (c) con ( ) (d) cont ( )
71 Which of the following commands can remove all the data from a table in a
MYSQL database?
a) DELETE b) DROP c) REMOVE d) ALTER
72 A candidate key, which is not the primary key of a table, is a/an _________.
a) Primary Key b) Foreign Key c) Candidate Key d) Alternate Key
74 Which function is used to display the total number of data values (except
NULL) from a column in a table?
a) sum() b) total() c) count() d) IS NOT NULL
76 ______ command is used to remove primary key from the table in SQL.
(a) update (b)remove (c) alter (d)drop
77 Which of the following commands will delete the table from MYSQL
database?
(a) DELETE TABLE (b) DROP TABLE (c) REMOVE TABLE (d) ALTER TABLE
78 _________ is a non-key attribute, whose values are derived from the primary key of
some other table.
(a) Primary Key (b) Foreign Key (c) Candidate Key
79 The SELECT statement when combined with __________ clause, returns records
without repetition.
(a) DESCRIBE (b) UNIQUE (c) DISTINCT (d) NULL
80 Which function is used to display the total number of records from table in a database?
(a) sum(*) (b) total(*) (c) count(*) (d) return(*)
81 Which function is used to display the total number of records from table in a database?
(a) sum(*) (b) total(*) (c) count(*) (d) return(*)
85 Which of the following query is incorrect? Assume table EMPLOYEE with attributes
EMPCODE, NAME, SALARY and CITY.
(a) SELECT COUNT(*) FROM EMPLOYEE;
(b) SELECT COUNT(NAME) FROM EMPLOYEE;
(c) SELECT AVG(SALARY) FROM EMPLOYEE;
(d) SELECT MAX(SALARY) AND MEAN(SALARY) FROM EMPLOYEE;
86 Which one of the following syntax is correct to establish a connection between Python and
MySQL database using the function connect( ) of [Link] package? Assume that
import [Link] as mycon is imported in the program.
(a) [Link](host = “hostlocal”, user = “root”, password = “MyPass”)
(b) [Link](host = “localhost”, user = “root”, passwd = “MyPass”, database =
“test”)
(c) [Link](“host”=“localhost”, “user”= “root”, “passwd”=”MyPass”, “database”=
“test”)
(d) [Link](“localhost” = host, “root”=user, “MyPass”=passwd)
91 Which of the following is not a method for fetching records from MySQL table using
Python interface?
a) fetchone() b) fetchrows() c) fetchall() d) fetchmany()
92 _____________ command is used to add a new column into an existing table in SQL.
(a) UPDATE (b) INSERT (c) ALTER (d) CREATE
95 In MYSQL database, if a table, BOOK has degree 8 and cardinality 7, and another table,
SALE has degree 4 and cardinality 7, what will be the degree and cardinality of the
Cartesian product of BOOK and SALE ?
a) 32 , 49 b) 12, 49 c) 12 ,14 d) 32,14
96 The SQL keyword ---------------- is used in SQL expression to select records based on
patterns
102 Table A has 3 rows and 4 columns and Table B has 5 rows and 6 columns. What is
the degree and cardinality of Cartesian product of A and B?
a) Degree is 15 and Cardinality is 15 b) Degree is 10 and Cardinality is 10
c) Degree is 10 and Cardinality is 15 d) Degree is 15 and Cardinality is 10
104 Which join combines each row from the first table with every row from the
second table to make the result set?
a. CROSS JOIN b. OUTER JOIN c. INNER JOIN d. EQUI JOIN
105 Which of the following constraint is used to prevent a duplicate value in a record?
(a) Empty (b) check (c) primary key (d) unique
106 The structure of the table/relation can be displayed using __________ command.
(a) view (b) describe (c) show (d) select
107 Which of the following clause is used to remove the duplicating rows from a select
statement?
(a) or (b) distinct (c) any (d)unique
108 Which of the following method is used to create a connection between the MySQL
database and Python?
(a) connector ( ) (b) connect ( ) (c) con ( ) (d) cont ( )
114 Which of the following is not valid cursor function while performing database operations
using python. Here Mycur is the cursor object?
(a) [Link]() (b) [Link]() (c) [Link](n) (d) [Link]()
115 command is used to remove the tuple from the table in SQL.
(a) update (b) remove (c) alter (d) delete
116 In MYSQL database, if a table, Emp has degree 10 and cardinality 5, and
another table, Dept has degree 5 and cardinality 10, what will be the degree
and cardinality of the Cartesian product of Emp and Dept ?
a. 50,15 b. 15,50 c. 50,50 d. 15,15
119 Which of the following commands will delete the contents of the table from MYSQL
database?
(a) DELETE (b) DROPTABLE (c) REMOVETABLE (d) ALTERTABLE
122 Which function is used to establish connection between python and SQL database?
(a) connection (b) connect (c) getconnection (d) getconnect
127 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 ()
128 The data types CHAR (n) and VARCHAR (n) are used to create _______ and _______
types of string/text fields in a database.
(a) Fixed, equal (b) Equal, variable (c) Fixed, variable (d) Variable, equal
132 A(n) _________in a table represents a logical relationship among a set of values.
(a) Attribute (b) Key (c) Tuple (d) Entry
133 Name the method which is used for displaying only one resultset.
(a) fetchmany (b) fetchno (c) fetchall (d) fetchone
135 Which is the subset of SQL commands used to manipulate database structure including
tables?
(a) Data Definition Language (DDL) (b) Data Manipulation Language (DML)
(c) Both (a) and (b) (d) None
140 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
141 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;
142 In SQL, which command is used to SELECT only one copy of each set of duplicable rows
(a) SELECT DISTINCT (b) SELECT UNIQUE
(c) SELECT DIFFERENT (d) All of the above
144 Which of the following sublanguages of SQL is used to query information from the data
base and to insert tuples into, delete tuples from, and modify tuples in the database?
(a) DML (Data Manipulation Language) (b) DDL (Data Definition Language)
(c) Query (d) Relational Schema
146 Which of the following is not a legal method for fetching records from database from
within Python?
(a) fetchone() (b) fetchtwo() (c) fetchall() (d) fetchmany()
148 Which of the following attributes can be considered as a choice for primary key?
(a)Name (b)Street (c) Roll No (d) Subject
150 What SQL statement do we use to display the record of all students whose last name
contains 5 letters ending with “A”?
(a) SELECT * FROM STUDENTS WHERE LNAME LIKE ‘_ _ _ _A’;
(b) SELECT * FROM STUDENTS WHERE LNAME LIKE ‘ _ _ _ _ _’;
(c) SELECT * FROM STUDENTS WHERE LNAME LIKE ‘ ????A’;
(d) SELECT * FROM STUDENTS WHERE LNAME LIKE ‘*A’;
152 Which of the following will you use in the following query to display the unique values of
the column dept_name?
SELECT _____________ dept_name FROM Company;
(a)All (b) From (c) Distinct (d) Name
154 With SQL, how do you select all the records from a table named “Students” where the
value of the column “FirstName” ends with an “a”?
(a) SELECT * FROM Students WHERE FirstName =’a’
(b) SELECT * FROM Students WHERE FirstName LIKE ‘a%’
(c) SELECT * FROM Students WHERE FirstName LIKE ‘%a’
(d) SELECT * FROM Students WHERE FirstName =’%a%’
157 To open a connector to Mysql database, which statement is used to connect with mysql?
(a) Connector (b) Connect (c) password (d) username
158 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
159 Which connector is used for linking the database with Python code?
(a) MySQL-connector (b) YesSQL: connector
(c) PostSQL: connector (d) None of the above
160 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) 50000
161 SQL applies conditions on the groups through _____ clause after groups have been
formed.
a) Group by (b) With (c) Where (d) Having
164 Which operator tests column for the absence of data (i.e., NULL value) ?
(a) EXISTS operator (b) NOT operator (c) IS operator (d) None of these
166 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
167 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
168 Where and Having clauses can be used interchangeably in SELECT queries?
(a) True (b) False (c) Only in views (d) With order by
167 A______ is property of the entire relation, which ensures through its value that each
tuple is unique in a relation.
(a) Rows (b) Key (c) Attribute (d) fields
168 The operation whose result contains all pairs of tuples from the two relations, regardless of
whether their attribute values match.
(a) Join (b) Cartesian product (c) Intersection (d) Set difference
170 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
171 The SQL keyword_______ is used to specify the table(s) that contains the data to be
retrieved.
172 To remove duplicate rows from the result of a query, specify the SQL qualifier________
in select list.
173 To obtain all columns, use a(n) _________ instead of listing all the column names in the
select list.
174 The SQL _______ clause contains the condition that specifies which rows are to the
selected.
175 To sort the rows of the result table, the _________ ________ clause is specified.
176 Columns can be sorted in descending sequence by using the SQL keyword
____________
177 When two conditions must both be true for the rows to be selected, the conditions are
separated by the SQL keyword ________
178 To refer to a set of values needed for a condition, we can use the SQL operation
__________
179 The SQL built-in function ________ totals values in numeric columns.
180 The SELECT clause _________ is used to collect those rows that have the same value in
a specified column.
181 The SQL built-in function __________ computes the number of rows in a table.
182 To exclude one or more values (a list of values) using a condition, the SQL keyword
________ ________ should be used.
183 ______________ method returns the result set in the form of tuples containing the
records or rows returned by the sql table.
184 The ______________ function works with data of multiple rows at a time and returns
aggregated value.
185 To specify filtering condition for groups, the _____________ clause is used in MYSQL.
186 To sort the result set in descending order, ___________ keyword is used with ORDER
BY.
187 The condition in a WHERE clause in a SELECT query can refer to only one value
188 SQL provides the AS keyword, which can be used to assign meaningful column names to
the results of queries using the SQL built-in functions.
189 The rows of the result relation produced by a SELECT statement can be sorted but only by
one column.
190 SELECT DISTINCT is used if a user wishes to see duplicate columns in a query.
191 The HAVING clause acts like a WHERE clause, but it identifies groups that meet a
criterion, rather than rows.
192 The qualifier DISTINCT must be used in an SQL statement when we want to Eliminate
duplicate rows.
193 DISTINCT and its counterpart, ALL, can be used more than once in a SELECT statement.
194 The SQL statement: SELECT salary + Comm AS Total FROM Emp; adds two fields salary
and comm from each row together and lists the results in a column named Total.
196 Data manipulation language (DML) commands are used to define a database, including
creating, altering, and dropping tables and establishing constraints.
197 The keyword LIKE can be used in a WHERE clause to refer to a range of values.
198 The SQL keyword GROUP BY instructs the DBMS to group together those rows that have
the same value in a column.
199 The keyword BETWEEN can be used in a WHERE clause to refer to a range of values.
200 Read operation on any table means to fetch some useful information from the table.
201 Use fetchall() method to retrieve only one value from a database table.
202 DISTINCT and its counterpart, ALL, can be used together on single field in a SELECT
statement.
206 The ORDER BY clause combines all those records that have identical values in a particular
field or a group of fields.
207 The WHERE clause is used to specify filtering conditions for groups.
208 DISTINCT option causes a group function to consider only the unique values of the
argument expression.
209 By default, ORDER BY clause sorts the result set in descending order.
210 COUNT () function ignores duplicate and null values while counting the records.
213 SUM () function is used to count the total number of records in a table.
214 Argument type of AVG () function can be numeric or string data type.
215 MySQL statement to delete a table STUDENT from the database SCHOOL is
DELETE TABLE STUDENT;
216 Where and Having clauses can be used interchangeably in SQL queries.
221 Which SQL statement is used to display all the data from PRODUCT table in the
decreasing order of PRICE?
a. SELECT * FROM PRODUCT ORDER PRICE BY DESC ;
b. SELECT * FROM PRODUCT PRICE ORDER BY DESC;
c. SELECT * FROM PRODUCT ORDER BY DESC PRICE;
d. SELECT * FROM PRODUCT ORDER BY PRICE DESC;
222 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 ()
225 Which SQL statement is used to display all the data from ITEMS table where
INAME is ending with ‘L’?
a. SELECT * FROM ITEMS WHERE INAME LIKE ‘L%’;
b. SELECT * FROM ITEMS WHERE INAME LIKE ‘%L’;
c. SELECT * FROM ITEMS WHERE INAME LIKE ‘%L%’;
d. SELECT * FROM ITEMS WHERE INAME LIKE ‘_L_’;
227 _________ is an attribute, whose values are Unique and not null.
(A) Primary Key (B)Foreign Key (C)Candidate Key (D)Alternate Key
231 .To di p y the det i of emp oyee h ving ‘e’ in their name in descending order of salary. The
correct
SQL statement is:
(a) SELE T*FROM emp WHERE en me L KE “e%” ORDER BY SAL;
(b) SELE T*FROM emp ORDER BY SAL DES WHERE en me L KE “%e%”;
(c) SELE T*FROM emp WHERE en me L KE “%e%” ORDER BY DES SAL;
(d) SELE T*FROM emp WHERE en me L KE “%e%” ORDER BY SAL DES ;
233
234
235
236
237
238
239
240