Stored Procedures, Triggers, and Views

Intermediate Updated March 20, 2025

🛠️ Stored Procedures, Triggers, and Views

These objects encapsulate logic for reusable, optimized operations:

Stored Procedure Example:

CREATE PROCEDURE GetBooksByAuthor
    @AuthorName NVARCHAR(100)
AS
BEGIN
    SELECT * FROM Books WHERE Author = @AuthorName;
END;

Trigger Example:

CREATE TRIGGER trg_BookInsert
ON Books
AFTER INSERT
AS
BEGIN
    PRINT 'A new book has been added.';
END;

View Example:

CREATE VIEW vw_RecentBooks AS
SELECT Title, PublishedYear FROM Books WHERE PublishedYear > 2000;