Database Questions and Answers – Basic SQL Operations

This set of Database Multiple Choice Questions & Answers (MCQs) focuses on “Basic SQL Operations”.

1.

SELECT name ____ instructor name, course id
FROM instructor, teaches
WHERE instructor.ID= teaches.ID;

Which keyword must be used here to rename the field name?
a) From
b) Rename
c) As
d) Join
View Answer

Answer: c
Explanation: As keyword is used to rename.
advertisement
advertisement

2.

SELECT * FROM employee WHERE dept_name="Comp Sci";

In the SQL given above there is an error . Identify the error.
a) Dept_name
b) Employee
c) “Comp Sci”
d) From
View Answer

Answer: c
Explanation: For any string operations single quoted(‘) must be used to enclose.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

3.

advertisement
SELECT emp_name
FROM department
WHERE dept_name LIKE ’ _____ Computer Science’;

Which one of the following has to be added into the blank to select the dept_name which has Computer Science as its ending string?
a) %
b) _
c) ||
d) $
View Answer

Answer: a
Explanation: The % character matches any substring.
advertisement

4. ’_ _ _ ’ matches any string of ______ three characters. ’_ _ _ %’ matches any string of at ______ three characters.
a) Atleast, Exactly
b) Exactly, Atleast
c) Atleast, All
d) All, Exactly
View Answer

Answer: b
Explanation: None.

5.

SELECT name
FROM instructor
WHERE dept name = ’Physics’
ORDER BY name;

By default, the order by clause lists items in ______ order.
a) Descending
b) Any
c) Same
d) Ascending
View Answer

Answer: d
Explanation: Specification of descending order is essential but it not for ascending.

6.

SELECT *
FROM instructor
ORDER BY salary ____, name ___;

To display the salary from greater to smaller and name in ascending order which of the following options should be used?
a) Ascending, Descending
b) Asc, Desc
c) Desc, Asc
d) Descending, Ascending
View Answer

Answer: c
Explanation: None.

7.

SELECT name
FROM instructor
WHERE salary <= 100000 AND salary >= 90000;

This query can be replaced by which of the following ?
a)

SELECT name
FROM instructor
WHERE salary BETWEEN 90000 AND 100000;

b)

SELECT name
FROM employee
WHERE salary <= 90000 AND salary>=100000;

c)

SELECT name
FROM employee
WHERE salary BETWEEN 90000 AND 100000;

d)

SELECT name
FROM instructor
WHERE salary BETWEEN 100000 AND 90000;
View Answer
Answer: a
Explanation: SQL includes a between comparison operator to simplify where clauses that specify that a value be less than or equal to some value and greater than or equal to some other value.
 
 

8.

SELECT instructor.*
FROM instructor, teaches
WHERE instructor.ID= teaches.ID;

This query does which of the following operation?
a) All attributes of instructor and teaches are selected
b) All attributes of instructor are selected on the given condition
c) All attributes of teaches are selected on given condition
d) Only the some attributes from instructed and teaches are selected
View Answer

Answer: b
Explanation: The asterisk symbol “ * ” can be usedin the select clause to denote “all attributes.”

9. In SQL the spaces at the end of the string are removed by _______ function.
a) Upper
b) String
c) Trim
d) Lower
View Answer

Answer: c
Explanation: The syntax of trim is Trim(s); where s-string.

10. _____ operator is used for appending two strings.
a) &
b) %
c) ||
d) _
View Answer

Answer: c
Explanation: || is the concatenation operator.

Sanfoundry Global Education & Learning Series – Database Management System.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.