0% found this document useful (0 votes)
2 views2 pages

Tuesday, June 17, 2025 5:57 PM: Durability: Committed Permanently Saved System Crashes

The document outlines key SQL concepts including views, transactions, stored procedures (SP), functions, and triggers. It explains the differences between views and tables, the ACID properties of transactions, and the characteristics of stored procedures and functions. Additionally, it describes triggers, their types, and how they interact with stored procedures, along with examples of SQL commands for managing triggers.

Uploaded by

Raj Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Tuesday, June 17, 2025 5:57 PM: Durability: Committed Permanently Saved System Crashes

The document outlines key SQL concepts including views, transactions, stored procedures (SP), functions, and triggers. It explains the differences between views and tables, the ACID properties of transactions, and the characteristics of stored procedures and functions. Additionally, it describes triggers, their types, and how they interact with stored procedures, along with examples of SQL commands for managing triggers.

Uploaded by

Raj Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL

Tuesday, June 17, 2025 5:57 PM

✓ View: A virtual table based on a SELECT query. It does not store data itself.
✓ Can a view be updated? Yes, if it's a simple view on a single table without joins or aggregates.
✓ Difference between View and Table?
▪ View: Virtual, no data storage.
▪ Table: Physical, stores data.
✓ Indexed View: A view that is materialized and stored physically with a unique clustered index to boost
performance.

✓ Transactions:
▪ A transaction is a logical unit of work that must be either fully completed/commit or fully rolled
back.
✓ ACID
▪ Atomicity: Atomicity ensures that either all operations in a transaction are completed
successfully, or none at all. If any part fails, the entire transaction is rolled back.
▪ Consistency: Data should be valid according to all defined rules
▪ Isolation: Isolation ensures that concurrent transactions do not interfere with each other.
▪ Durability: Once a transaction is committed, the changes are permanently saved, even if the
system crashes afterward.

▪ Atomicity: All or nothing execute


▪ Consistency: data should be valid
▪ Isolation: don't interfere each other
▪ Durability: committed…permanently saved…system crashes

▪ Atomicity – All or nothing


▪ Consistency – Data remains valid
▪ Isolation – Transactions run independently
▪ Durability – Changes are permanent

✓ Store Procedure vs Function


▪ SP may or may not return value. Function must return value.
▪ SP can return one or more value. Function must return a value
▪ SP can have input/output parameter. Function can have input parameter.
▪ We can call function inside SP. We cannot call SP inside function
▪ We can use try-catch exception handling in SP. We cannot use try-catch in Function.
▪ We can use transaction inside SP. We cannot use transaction inside function.
▪ SP can perform DML operations. Function cannot perform INSERT, UPDATE, DELETE
✓ Function: A function in SQL Server is a reusable database object that performs a task, returns a value,
and can be used in SQL queries (unlike stored procedures).
✓ Scalar Function: Returns a single scalar value (e.g., int, varchar)
✓ Table-Valued Function (TVF): Returns a table (similar to a result set)

✓ SP:
▪ A Stored Procedure is a precompiled collection of one or more SQL statements that are stored
and executed on the SQL Server.
▪ Can a procedure return a value? (Yes, via RETURN or OUTPUT parameters)
▪ What’s the max number of parameters? (2,100)

Answer Page 1
▪ What’s the max number of parameters? (2,100)
▪ Can you use transactions inside a procedure? (Yes, with BEGIN TRANSACTION, COMMIT,
ROLLBACK)
▪ Can a procedure call itself? (Yes, it supports recursion)

✓ Trigger: A trigger is a special type of stored procedure that automatically executes in response to
specific events on a table or view, such as INSERT, UPDATE, or DELETE.
✓ Types:
▪ DML Triggers
○ After Triggers
○ INSTEAD OF Triggers
▪ DDL Triggers
▪ LOGON Triggers
✓ Can a trigger call a stored procedure? Yes
✓ Can we use transaction in a trigger? Yes
✓ Can a trigger be recursive? Yes
✓ Can a table have multiple triggers for the same event? Yes
✓ How to check existing triggers in SQL Server?
-- List all triggers
SELECT * FROM sys.triggers;
-- Triggers on a specific table
SELECT * FROM sys.triggers WHERE parent_id = OBJECT_ID('TableName');
✓ How do you disable or enable a trigger?
DISABLE TRIGGER TriggerName ON TableName;
ENABLE TRIGGER TriggerName ON TableName;
✓ What is the difference between AFTER and INSTEAD OF triggers?
✓ SP vs Trigger:
SP Trigger
Call manually automatically
Input/Output Parameter ✓ X
Return value ✓ X

Answer Page 2

You might also like