Font size
WorksheetsSQL
Total questions: 45
Worksheet time: 22mins
Which SQL function is used to count the number of rows in a SQL query?
COUNT()
NUMBER()
SUM()
COUNT(*)
If you don’t specify ASC or DESC after a SQL ORDER BY clause, the following is used by default
ASC
DESC
There is no default value
None of the mentioned
With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” ends with an “a”?
SELECT * FROM Persons WHERE FirstName=’a’
SELECT * FROM Persons WHERE FirstName LIKE ‘a%’
SELECT * FROM Persons WHERE FirstName LIKE ‘%a’
SELECT * FROM Persons WHERE FirstName=’%a%’
What does the ALTER TABLE clause do?
The SQL ALTER TABLE clause modifies a table definition by altering, adding, or deleting table columns and/or constraints
The SQL ALTER TABLE clause is used to insert data into database table
THE SQL ALTER TABLE deletes data from database table
The SQL ALTER TABLE clause is used to delete a database table
The UPDATE SQL clause can _____________
update only one row at a time
update more than one row at a time
delete more than one row at a time
delete only one row at a time
How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?
UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
SQL query to find all the cities whose humidity is 95.
SELECT city WHERE humidity = 95
SELECT city FROM weather WHERE humidity = 95
SELECT humidity = 89 FROM weather
SELECT city FROM weather
SQL query to find the temperature in increasing order of all cities.
SELECT city FROM weather ORDER BY temperature
SELECT city, temperature FROM weather
SELECT city, temperature FROM weather ORDER BY temperature
SELECT city, temperature FROM weather ORDER BY city
Find the name of those cities with temperature and condition whose condition is either sunny or cloudy but temperature must be greater than 70.
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ OR temperature > 70
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ OR temperature > 70
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ AND temperature > 70
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ AND temperature > 70
The command to remove rows from a table ‘CUSTOMER’ is __________________
DROP FROM CUSTOMER
UPDATE FROM CUSTOMER
REMOVE FROM CUSTOMER
DELETE FROM CUSTOMER WHERE
Find the names of these cities with temperature and condition whose condition is neither sunny nor cloudy.
SELECT city, temperature, condition FROM weather WHERE condition NOT IN (‘sunny’, ‘cloudy’)
SELECT city, temperature, condition FROM weather WHERE condition NOT BETWEEN (‘sunny’, ‘cloudy’)
SELECT city, temperature, condition FROM weather WHERE condition IN (‘sunny’, ‘cloudy’)
SELECT city, temperature, condition FROM weather WHERE condition BETWEEN (‘sunny’, ‘cloudy’);
If you were wanting to filter data, which clause would you use?
Where
Order by
From
Select
Which statement allows us to add a record to a table?
Add To
Update To
Add Into
Insert Into
Less than or equal to?
>=
=>
=<
<=
Which character returns all the data found in a table?
%
#
*
/
You are required to update the phone number for only the DesignerID "SMI01" in the "Designer" table. Which of these would successfully do that?
UPDATE Designer SET PhoneNo = '01224123456'
UPDATE Designer (PhoneNo) VALUES ('01224123456')
UPDATE Designer SET PhoneNo = '01224123456' WHERE DesignerID = 'SMI01'
UPDATE PhoneNo = '01224123456' FROM Designer WHERE DesignerID = 'SMI01'
Which of the following is not a database data type?
text
number
array
date
Referential Integrity is
System of rules
System of data
Table constraints
is related to Primary key
______________ constraint prevents NULL values
UNIQUE
NOT NULL
NULL
FOREIGN KEY
A primary key can be NULL in the table? TRUE or FALSE
TRUE
FALSE
What would the SQL query pictured do?
Find all the men
Find all of the female writers
Find all of Elgar's friends
Find all the male writers
Find all the fish
Which SQL statement is used to return only different values?
SELECT UNIQUE
SELECT DISTINCT
SELECT DIFFERENT
With SQL, how can you insert "Olsen" as the "LastName" in the "Persons" table?
INSERT INTO Persons (LastName) VALUES ('Olsen')
INSERT INTO Persons ('Olsen') INTO LastName
INSERT ('Olsen') INTO Persons (LastName)
How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table?
MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'
MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'
With SQL, how can you delete the records where the "FirstName" is "Peter" in the Persons Table?
DELETE ROW FirstName='Peter' FROM Persons
DELETE FirstName='Peter' FROM Persons
DELETE FROM Persons WHERE FirstName = 'Peter'
With SQL, how can you return the number of records in the "Persons" table?
SELECT NO(*) FROM Persons
SELECT COUNT(*) FROM Persons
SELECT LEN(*) FROM Persons
Which of the following is NOT a GROUP BY function?
MAX
MIN
NVL
AVG
Which of the following functions can be used without GROUP BY clause in SELECT query? (Select all that apply)
COUNT
MAX
MIN
AVG
Which of the following SELECT query returns the department number with maximum salary compensated to an employee? (Consider the table structure as given)
SELECT department_id , max(salary ) FROM employees ;
SELECT department_id , max(salary ) FROM employees GROUP BY department_id ;
SELECT max(salary ) FROM employees GROUP BY department_id ;
SELECT max(salary ) FROM employees ;
Which of the following statements are true about the COUNT function?
The COUNT function counts the number of rows
The COUNT(*) function counts the number of rows with duplicates and NULL values
The COUNT(DISTINCT) function counts the number of distinct rows
COUNT(*) is equivalent to COUNT(ALL)
A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.
SELECT COUNT (num) FROM t_count;
12
6
9
Throws exception because COUNT function doesn't works with NULL values
A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.
SELECT COUNT (DISTINCT num) FROM t_count;
12
6
9
Throws exception because COUNT function doesn't works with NULL values
Which SQL keyword is used to sort the result-set?
ORDER
SORT BY
SORT
ORDER BY
With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"?
SELECT * FROM Persons SORT 'FirstName' DESC
SELECT * FROM Persons ORDER BY FirstName DESC
SELECT * FROM Persons SORT BY 'FirstName' DESC
SELECT * FROM Persons ORDER FirstName DESC
Which operator is used to select values within a range?
Next ❯
RANGE
WITHIN
BETWEEN
The NOT NULL constraint enforces a column to not accept empty values.
Next ❯
TRUE
FALSE
Which product is returned in a join query having no join condition?
Equi join
Cartesian
Both Equi joins and Cartesian
Natural
The Cartesian product is also called _________ join
Equi join
Natural
Unrestricted join
Restricted join
In which type of join, the join condition contains an equality operator?
Equi join
Natural
Left join
Right join
In which type of join, the join condition contains an equality operator?
Equi join
Natural
Left join
Right join
In which type of join, duplicate columns are there?
Equi join
Natural
Left join
Right join
With SELECT statement used for joins, the ON subclause produces _______ join
Equi join
Natural
Left join
Right join
