SQL Server (SSMS) Final Examination
**Coverage:** Stored Procedures, Views, Triggers (with Inserted/Deleted)
Answer all questions. This exam is divided into three parts: Multiple Choice, True or False,
and Practical Scenarios.
Part I – Multiple Choice (1 point each)
Choose the best answer.
1. What is a stored procedure primarily used for?
A. Data storage
B. Encapsulating business logic
C. Defining table schema
D. Displaying errors
Answer: B
2. What command executes a stored procedure?
A. RUN
B. PERFORM
C. EXEC
D. CALL
Answer: C
3. Which of the following is a key advantage of using views?
A. Permanent data storage
B. Simplified data access
C. Replaces all triggers
D. Executes automatically
Answer: B
4. Which SQL object fires automatically in response to table events?
A. Stored procedure
B. View
C. Trigger
D. Function
Answer: C
5. Which virtual table holds new data in a trigger?
A. updated
B. changed
C. inserted
D. incoming
Answer: C
6. What does `SET NOCOUNT ON;` do in a stored procedure?
A. Counts NULL rows
B. Disables triggers
C. Prevents row count messages
D. Adds a condition
Answer: C
7. Which clause is used to create a view?
A. MAKE VIEW
B. ADD VIEW
C. SELECT VIEW
D. CREATE VIEW
Answer: D
8. Which of the following is NOT true about triggers?
A. Can be used for auditing
B. Executes automatically
C. Requires manual execution
D. Can reference inserted/deleted
Answer: C
9. What SQL object allows filtering access to a subset of data?
A. Cursor
B. View
C. Table
D. Index
Answer: B
10. Triggers can be used with which DML statements?
A. INSERT
B. UPDATE
C. DELETE
D. All of the above
Answer: D
...remaining questions are available in full version.
11. What is a virtual table within a trigger that contains the old version of the data?
A. dropped
B. changed
C. deleted
D. rollback
Answer: C
12. A view is:
A. A table copy
B. A stored result set
C. A virtual table
D. A stored procedure
Answer: C
13. Which of the following allows conditional logic in SQL Server?
A. Views
B. Triggers
C. Tables
D. Stored Procedures
Answer: D
14. Which of the following can be used to log changes in a table?
A. Table
B. Trigger
C. Index
D. Cursor
Answer: B
15. Which DDL command removes a stored procedure?
A. DELETE
B. REMOVE
C. DROP
D. ERASE
Answer: C
16. What is required to update a view?
A. Index
B. Base table
C. Join
D. None
Answer: B
17. A trigger that replaces a DML operation is called:
A. AFTER
B. BEFORE
C. INSTEAD OF
D. ON DELETE
Answer: C
18. What are the two virtual tables available in DML triggers?
A. old, new
B. inserted, deleted
C. before, after
D. pre, post
Answer: B
19. A stored procedure is:
A. Executed at table creation
B. A table-like structure
C. Reusable SQL logic
D. Triggered by data changes
Answer: C
20. Which type of trigger is used most commonly?
A. INSTEAD OF
B. BEFORE
C. AFTER
D. SYSTEM
Answer: C
21. Which syntax defines a stored procedure?
A. CREATE FUNCTION
B. CREATE PROCEDURE
C. DEFINE PROC
D. START PROCEDURE
Answer: B
22. What keyword is used to output data from a stored procedure?
A. OUT
B. RETURN
C. OUTPUT
D. SEND
Answer: C
23. Views are updated only if:
A. They include joins
B. They contain GROUP BY
C. They are simple and direct
D. They are stored procedures
Answer: C
24. Triggers can enforce:
A. Application logic
B. Security policies
C. Business rules
D. Views
Answer: C
25. Triggers are attached to:
A. Views only
B. Tables only
C. Tables or views
D. Stored procedures
Answer: C
26. Which one is precompiled?
A. Trigger
B. View
C. Stored Procedure
D. Function
Answer: C
27. What clause is used in triggers to check updated values?
A. ON CHANGE
B. ON MODIFY
C. inserted and deleted
D. updated table
Answer: C
28. Which keyword starts the SQL block inside a procedure or trigger?
A. START
B. INITIATE
C. BEGIN
D. EXECUTE
Answer: C
29. Which SQL block helps with rollback operations?
A. TRANSACTION
B. REVERT
C. SAVE
D. GOTO
Answer: A
30. Which is a correct trigger event?
A. ON SELECT
B. ON VIEW
C. ON DELETE
D. ON CALL
Answer: C
Part II – True or False (1 point each)
31. A view stores data physically on disk.
Explanation: False. Views are virtual tables, they do not store data themselves.
32. Stored procedures can accept both input and output parameters.
Explanation: True. Parameters are supported for flexible logic.
33. A trigger executes only when manually called.
Explanation: False. Triggers fire automatically on data changes.
34. Views can simplify access to complex data queries.
Explanation: True. Views hide complex joins and filters.
35. You can write conditional logic in a view using IF statements.
Explanation: False. Conditional logic like IF is not allowed in views.
36. The inserted table in a trigger holds old data.
Explanation: False. inserted holds new data; deleted holds old.
37. You can call a view using EXEC ViewName.
Explanation: False. Views are accessed via SELECT, not EXEC.
38. Stored procedures can include transactions and error handling.
Explanation: True. They can use BEGIN TRAN, TRY...CATCH, etc.
39. Triggers can affect performance if not used carefully.
Explanation: True. They can cause hidden overhead if overused.
40. Triggers support only INSERT operations.
Explanation: False. Triggers support INSERT, UPDATE, DELETE.
Part III – Practical Scenarios (2 points each)
41. Which query creates a view of active employees?
A. CREATE VIEW ActiveEmp AS SELECT * FROM Employees WHERE IsActive = 1;
B. SELECT * FROM Employees WHERE IsActive = 1;
C. CREATE TABLE ActiveEmp AS SELECT * FROM Employees;
D. EXEC CreateViewActiveEmp;
Answer: A
42. Create a stored procedure that accepts an employee ID and returns employee data.
A. CREATE PROCEDURE empData SELECT * FROM Employees;
B. CREATE PROCEDURE GetEmp(@ID INT) AS SELECT * FROM Employees WHERE
EmployeeID = @ID;
C. SELECT GetEmp FROM Employees;
D. CREATE FUNCTION GetEmpID() RETURNS TABLE;
Answer: B
43. What trigger logs department changes?
A. CREATE PROCEDURE logDeptChange...
B. CREATE TRIGGER trgDeptChange ON Employees AFTER UPDATE AS INSERT INTO
Log...
C. CREATE FUNCTION logChange();
D. CREATE VIEW LogChanges AS...
Answer: B
44. Select the syntax to call a stored procedure with parameters:
A. CALL GetEmp('5');
B. SELECT * FROM GetEmp(5);
C. EXEC GetEmp @ID = 5;
D. RUN GetEmp[5];
Answer: C
45. You want to check old and new values in a trigger. Which tables do you use?
A. old, new
B. pre, post
C. inserted, deleted
D. source, target
Answer: C
46. You want to stop row count messages in a procedure. What do you write?
A. NOCOUNT OFF
B. COUNT SET OFF
C. SET NOCOUNT ON
D. DISABLE ROWCOUNT
Answer: C
47. Select a correct DROP procedure syntax:
A. DELETE PROCEDURE GetEmp
B. DROP GetEmp
C. DROP PROCEDURE GetEmp
D. REMOVE PROCEDURE GetEmp
Answer: C
48. Choose the right way to SELECT from a view:
A. EXEC vwEmployee
B. SELECT FROM vwEmployee
C. SELECT * FROM vwEmployee
D. CALL vwEmployee()
Answer: C
49. Which command defines the start of a transaction?
A. START TRANSACTION
B. BEGIN
C. BEGIN TRAN
D. OPEN TRANSACTION
Answer: C
50. Which scenario is best for using a trigger?
A. To display all active records
B. To compute averages
C. To log all deletes from a table
D. To create indexes
Answer: C