Stored Procedures, Triggers, and Views
🛠️ 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;