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
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
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
Explanation: We can pass parameters to a stored procedure, so that the stored procedure executes based on the parameter value that is passed.
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)
CREATE PROCEDURE procedure_name Sql_statements GO;
d)
CREATE PROCEDURE procedure_name AS Sql_statements;
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
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
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
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
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;
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
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.