1.
Construct a stored procedure, named usp_GetLastName, that accepts one input parameter named EmployeeID and returns the last name of the employee.
2.
Create stored procedure usp_get_employees_salary_above_35000 that returns all employees’ first and last names for whose salary is above 35000. The result should be sorted by first_name then by last_name alphabetically.
3.
A named set of SQL statements that are considered when a data modification occurs are called:
Correct Answer
C. Triggers.
Explanation
Triggers are a named set of SQL statements that are executed automatically when a specific event, such as a data modification, occurs in the database. They are used to enforce business rules, maintain data integrity, and automate certain actions. Stored procedures, on the other hand, are named sets of SQL statements that are stored in the database and can be executed on demand. Treatments and trapdoors are not relevant terms in the context of SQL.
4.
All of the following are part of the coding structure for triggers EXCEPT:
Correct Answer
C. C) selection.
Explanation
Triggers in coding are used to automatically perform certain actions when a specific event occurs. The coding structure for triggers typically includes four components: event, condition, action, and selection. The event specifies the trigger point or the event that triggers the action. The condition specifies the criteria that must be met for the trigger to activate. The action specifies the specific task or action that is performed when the trigger is activated. However, selection is not a part of the coding structure for triggers, so the correct answer is C) selection.
5.
While triggers run automatically, ________ do not and have to be called.
Correct Answer
B. B) routines
Explanation
Routines are a set of instructions or procedures that need to be explicitly called in order to run. Unlike triggers, which are automatically executed in response to a specific event, routines require manual invocation. Therefore, routines are the correct answer to the question.
6.
SQL-invoked routines can be:
Correct Answer
C. C) all of the above.
Explanation
SQL-invoked routines can be both procedures and functions. Procedures are a set of SQL statements that perform a specific task and can be called multiple times. Functions, on the other hand, return a single value and can be used in SQL statements. Therefore, both procedures and functions are examples of SQL-invoked routines, making option C the correct answer.
7.
All of the following are advantages of SQL-invoked routines EXCEPT:
Correct Answer
A. A) flexibility.
Explanation
SQL-invoked routines, such as stored procedures or functions, provide several advantages. They enhance efficiency by reducing network traffic and improving performance. They promote sharability by allowing multiple users to access and execute the same routine. They also enhance security by allowing the database administrator to control access and permissions. However, flexibility is not an advantage of SQL-invoked routines as they are predefined and cannot be easily modified or adapted to changing requirements.
8.
A procedure is:
Correct Answer
D. D) all of the above.
Explanation
A procedure is a set of instructions or a sequence of actions that can be stored within a database. It is given a unique name to identify it and can be called or executed by using that name. Therefore, all of the given options are correct as a procedure is stored within the database, given a unique name, and called by name.
9.
Constraints are a special case of triggers.
Correct Answer
A. True
Explanation
Constraints are a special case of triggers because both are used to enforce rules and conditions on the data in a database. However, triggers are specific actions that are automatically executed when a certain event occurs, while constraints are rules that are applied to the data to ensure its integrity and consistency. Therefore, it can be said that constraints are a subset or a special case of triggers, as they are a type of rule that can be enforced through triggers.
10.
Triggers can be used to ensure referential integrity, enforce business rules, create audit trails and replicate tables, but cannot call other triggers.
Correct Answer
B. False
Explanation
Triggers can indeed be used to ensure referential integrity, enforce business rules, create audit trails, and replicate tables. However, triggers can also call other triggers. Therefore, the given statement that triggers cannot call other triggers is incorrect.
11.
Triggers have three parts: the event, the condition, and the action.
Correct Answer
A. True
Explanation
This statement is true because triggers in programming typically consist of three components: the event, which is the specific action or occurrence that initiates the trigger; the condition, which is a set of criteria that must be met for the trigger to activate; and the action, which is the specific task or set of tasks that the trigger performs when it is activated. These three parts work together to create a trigger that responds to specific events and conditions in a program.
12.
A function has only input parameters but can return multiple values.
Correct Answer
B. False
Explanation
A function can have both input parameters and return a single value or no value at all. However, it cannot directly return multiple values. To return multiple values, we can use data structures like arrays or objects, or we can use output parameters to modify the values of variables passed as arguments to the function. Therefore, the statement that a function can return multiple values is false.
13.
A procedure is run by calling it by its name.
Correct Answer
A. True
Explanation
This statement is true because in most programming languages, a procedure or function is executed by calling it by its name. The name of the procedure is used as a reference to locate and execute the code within the procedure. By calling the procedure, the program transfers control to the code inside the procedure and executes it.
14.
The views are created by executing a CREATE VIEW SQL command.
Correct Answer
A. True
Explanation
Views in a database are created by executing a CREATE VIEW SQL command. This command allows users to create a virtual table that is based on the result of a query. The view can then be used to retrieve data from multiple tables or to simplify complex queries. By creating views, users can easily access and manipulate data without needing to write complex queries each time. Therefore, the statement that views are created by executing a CREATE VIEW SQL command is true.
15.
The variables in the triggers are declared using
Correct Answer
B. B) @
Explanation
In many programming languages and systems, including databases and event-driven systems, the "@" symbol is commonly used to declare variables in triggers. This symbol is used to differentiate variables from other elements in the code and to indicate that a specific value will be assigned to the variable. Therefore, the correct answer is b) @.
16.
John creates a trigger on the Sales table. He is trying to enforce the business rule that no order can be created (inserted) with a total less than $20. However, it can be updated by a supervisor, if necessary. What must his code do to the Sales table if the test inside the trigger tries to insert an order with a total of $15?
Please select the best answer.
Correct Answer
B. B. Delete the row from the Sales table.
Explanation
The correct answer is B.
He needs to delete the data from the Sales table if the rule fails. A is incorrect because the Inserted table can never have any action performed on it other than a SELECT statement. C is incorrect because the trigger cannot know what to do if John doesn’t code for it. D is incorrect because, again, the Inserted table can only have data selected from it.
17.
If you insert data into the Category table that has an INSERT trigger on it, what happens to the data when the trigger fires?
Please select the best answer.
Correct Answer
A. A. The data resides in the Inserted and the Category tables.
Explanation
A is correct.
The data resides in the Inserted and the Category tables. B is incorrect because the data also resides in the Category table. C is incorrect because the data also resides in the Inserted table. D is incorrect because only UPDATE triggers affect both the Inserted and Deleted tables.
18.
What makes stored procedures faster than sending a Transact-SQL statement to SQL Server?
Please select the best answer.
Correct Answer
B. B. The query plan is compiled and cached on the server.
Explanation
The correct answer is B.
A stored procedure is compiled and its query plan is cached. A is incorrect because stored procedures are faster. C is incorrect because Transact-SQL statements do not have to be shorter in stored procedures. D is incorrect because the same number of commands are available to both.