SQL Questions and Answers – SQL Comments

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

1. Which of the following correctly defines a stored procedure in SQL?
a) A prepared SQL code which cannot be saved
b) A code that cannot be reused again
c) A code that can be saved and reused over and over again
d) A code that can be stored but cannot be reused
View Answer

Answer: c
Explanation: A stored procedure is a prepared SQL code that can be saved, so that the code can be reused over and over again.

2. If we have an SQL query that we write over and over again, which of the following is a better idea to make it less complex?
a) Use logical operators
b) Save it as a stored procedure
c) Write the query as many number of times as we want to execute
d) simplify it by using loops
View Answer

Answer: b
Explanation: If we have an SQL query that we write over and over again we can save it as a stored procedure and then just call it to execute the query to make the program less complex.

3. We cannot pass parameters to a stored procedure.
a) True
b) False
View Answer

Answer: b
Explanation: We can pass parameters to a stored procedure, so that the stored procedure executes based on the parameter value that is passed.
advertisement
advertisement

4. What is the syntax to create a stored procedure?
a)

CREATE PROCEDURE procedure_name
AS
Sql_statements
GO;

b)

CREATE PROCEDURE
AS
Sql_statements
GO;

c)

advertisement
CREATE PROCEDURE procedure_name
Sql_statements
GO;

d)

advertisement
CREATE PROCEDURE procedure_name
AS
Sql_statements;
View Answer
Answer: a
Explanation: The correct syntax for a stored procedure is:

CREATE PROCEDURE procedure_name
AS
Sql_statements
GO;

5. Which of the following statement(s) is used to execute a stored procedure?
a) EXECUTE procedure_name;
b) EXE procedure_name;
c) EXEC procedure_name;
d) EXE PROCEDURE procedure_name;
View Answer

Answer: c
Explanation: The syntax to execute a stored procedure is:

EXEC procedure_name;

6. A stored procedure is able to call another stored procedure.
a) True
b) False
View Answer

Answer: a
Explanation: A stored procedure can be called from any other stored procedure, just as we execute a stored procedure in a separate SQL query.

7. How many parameters can be passed to a stored procedure in SQL?
a) Only one
b) Two
c) Three
d) Any number
View Answer

Answer: d
Explanation: We can pass any number of parameters to a stored procedure. It may have zero parameters when the user doesn’t require passing any parameters to the procedure.

8. Where the stored procedures are stored in a database?
a) Database data dictionary
b) Database meta data
c) Database server
d) SQL server
View Answer

Answer: a
Explanation: Stored Procedure can be available to applications accessing a relational database system. They are actually stored in the database data dictionary.

9. Which of the following statements creates a stored procedure ‘MONEY’ with a parameter ‘note’?
a)

CREATE PROCEDURE money
AS
Sql_statements
GO;

b)

CREATE PROCEDURE money note varchar2(10)
AS
Sql_statements
GO;

c)

CREATE PROCEDURE money @note varchar2(10)
AS
Sql_statements
GO;

d)

CREATE money @note varchar2(10)
AS
Sql_statements
GO;
View Answer
Answer: c
Explanation: Any parameter added to a stored procedure must be preceded with @ symbol and must end with the data type of the parameter.

10. How many SQL statements can be written in a stored procedure?
a) One
b) Two
c) Three
d) Any number
View Answer

Answer: d
Explanation: We can use multiple select statements in a stored procedure SQL server. So, any number of SQL statements can be written in a stored procedure.

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

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.