Basic SQL
Basic SQL
1. Which SQL function is used to count the number of rows in a SQL query ?
a) COUNT()
b) NUMBER()
c) SUM()
d) COUNT(*)
3. Which of the following SQL clauses is used to DELETE tuples from a database table ?
a) DELETE
b) REMOVE
c) DROP
d) CLEAR
4. ___________removes all rows from a table without logging the individual row deletions.
a) DELETE
b) REMOVE
c) DROP
d) TRUNCATE
8. If you don’t specify ASC or DESC after a SQL ORDER BY clause, the following is used by default
a) ASC
b) DESC
c) There is no default value
d) None of the mentioned
12. 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” ?
a) SELECT * FROM Persons WHERE FirstName=’a’
b) SELECT * FROM Persons WHERE FirstName LIKE ‘a%’
c) SELECT * FROM Persons WHERE FirstName LIKE ‘%a’
d) SELECT * FROM Persons WHERE FirstName=’%a%’
13. With SQL, how can you return all the records from a table named “Persons” sorted descending by
“FirstName” ?
a) SELECT * FROM Persons SORT BY ‘FirstName’ DESC
b) SELECT * FROM Persons ORDER FirstName DESC
c) SELECT * FROM Persons SORT ‘FirstName’ DESC
d) SELECT * FROM Persons ORDER BY FirstName DESC
14. With SQL, how can you return the number of not null records in the “Persons” table ?
a) SELECT COUNT() FROM Persons
b) SELECT COLUMNS() FROM Persons
c) SELECT COLUMNS(*) FROM Persons
d) SELECT COUNT(*) FROM Persons
20. How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?
a) UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
b) MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
c) MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
d) UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
21. Which of the following command makes the updates performed by the transaction permanent in the
database ?
a) ROLLBACK
b) COMMIT
c) TRUNCATE
d) DELETE
22. Which TCL command undo all the updates performed by the SQL in the transaction ?
a) ROLLBACK
b) COMMIT
c) TRUNCATE
d) DELETE
24. SQL query to find the temperature in increasing order of all cities.
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
26. Find the names of these cities with temperature and condition whose condition is neither sunny nor
cloudy.
a) SELECT city, temperature, condition FROM weather WHERE condition NOT IN (‘sunny’,
‘cloudy’)
b) SELECT city, temperature, condition FROM weather WHERE condition NOT BETWEEN (‘sunny’,
‘cloudy’)
c) SELECT city, temperature, condition FROM weather WHERE condition IN (‘sunny’, ‘cloudy’)
d) SELECT city, temperature, condition FROM weather WHERE condition BETWEEN (‘sunny’,
‘cloudy’);
27. Find the name of those cities with temperature and condition whose condition is either sunny or
cloudy but temperature must be greater than 70.
a) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition =
‘cloudy’ OR temperature > 70
b) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition =
‘cloudy’ OR temperature > 70
c) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition =
‘cloudy’ AND temperature > 70
d) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition =
‘cloudy’ AND temperature > 70
28. Find all the tuples having temperature greater than ‘Paris’.
a) SELECT * FROM weather WHERE temperature > (SELECT temperature FROM weather WHERE
city = ‘Paris’
b) SELECT * FROM weather WHERE temperature > (SELECT * FROM weather WHERE city =
‘Paris’)
c) SELECT * FROM weather WHERE temperature > (SELECT city FROM weather WHERE city =
‘Paris’)
d) SELECT * FROM weather WHERE temperature > ‘Paris’ temperature
29. Find all the cities with temperature, condition and humidity whose humidity is in the range of 63 to
79.
a) SELECT * FROM weather WHERE humidity IN (63 to 79)
b) SELECT * FROM weather WHERE humidity NOT IN (63 AND 79)
c) SELECT * FROM weather WHERE humidity BETWEEN 63 AND 79
d) SELECT * FROM weather WHERE humidity NOT BETWEEN 63 AND 79
31. What type of join is needed when you wish to include rows that do not have matching values?
a) Equi-join
b) Natural join
c) Outer join
d) All of the Mentioned
32. What type of join is needed when you wish to return rows that do have matching values?
a) Equi-join
b) Natural join
c) Outer join
d) All of the Mentioned
33. Which of the following is one of the basic approaches for joining tables?
a) Subqueries
b) Union Join
c) Natural join
d) All of the Mentioned
34. The following SQL is which type of join: SELECT CUSTOMER_T. CUSTOMER_ID, ORDER_T.
CUSTOMER_ID, NAME, ORDER_ID FROM CUSTOMER_T,ORDER_T WHERE CUSTOMER_T.
CUSTOMER_ID = ORDER_T. CUSTOMER_ID?
a) Equi-join
b) Natural join
c) Outer join
d) Cartesian join
51. Select __________ from instructor where dept name= ’Comp. Sci.’;
Which of the following should be used to find the mean of the salary ?
a) Mean(salary)
b) Avg(salary)
c) Sum(salary)
d) Count(salary)
52. The ________ connective tests for set membership, where the set is a collection of values produced
by a select clause. The _________ connective tests for the absence of set membership.
a) Or, in
b) Not in, in
c) In, not in
d) In, or
53. Select ID, GPA from student grades order by GPA ____________
Inorder to give only 10 rank on the whole we should use :
a) Limit 10
b) Upto 10
c) Only 10
d) Max 10
54. Suppose we are given a view tot credits (year, num credits) giving the total number of credits taken
by students in each year.The query that computes averages over the 3 preceding tuples in the specified
sort order is :
a) SELECT YEAR, avg(num credits)
OVER (ORDER BY YEAR ROWS 3 preceding) AS avg total credits
FROM tot credits;
b) SELECT YEAR, avg(num credits)
OVER (ORDER BY YEAR ROWS 3 unbounded preceding) AS avg total credits
FROM tot credits;
c) SELECT YEAR, MIN(num credits)
OVER (ORDER BY YEAR ROWS 3 unbounded preceding) AS avg total credits
FROM tot credits;
d) SELECT YEAR, SUM(num credits)
OVER (ORDER BY YEAR ROWS 3 unbounded preceding) AS avg total credits
FROM tot credits;
56. Which server can join the indexes when only multiple indexes combined can cover the query ?
a) SQL
b) DBMS
c) RDBMS
d) All of the mentioned
57. Select ________ dept_name from instructor;
Here which of the following displays the unique values of the column ?
a) All
b) From
c) Distinct
d) Name
58. Select ID, name, dept name, salary * 1.1 where instructor;
The query given below will not give an error. Which one of the following has to be replaced to get the
desired output ?
a) Salary*1.1
b) ID
c) Where
d) Instructor
60. The ______ clause allows us to select only those rows in the result relation of the ____ clause that
satisfy a specified predicate.
a) Where, from
b) From, select
c) Select, from
d) From, where
68. Which of the following foreign key constraint specifies that the deletion fails with an error ?
a) NO ACTION
b) CASCADE
c) SET NULL
d) All of the mentioned