SQL Server Concepts Comparison
Report
Trigger vs Stored Procedure
Trigger:
- Automatically executed when a specific database event occurs (INSERT, UPDATE,
DELETE).
- Cannot be manually called.
- Commonly used for enforcing rules or logging changes automatically.
- Attached directly to a table or view.
Stored Procedure:
- Manually executed using EXEC or EXECUTE.
- Can accept input parameters and return results.
- Used for performing business logic, data manipulation, and complex operations.
- Not automatically linked to data changes.
Stored Procedure vs Function
Stored Procedure:
- Can return multiple result sets or none at all.
- Supports data modification (INSERT, UPDATE, DELETE).
- Cannot be called inside a SELECT statement.
- More flexible for large tasks.
Function:
- Must return a value (scalar or table).
- Cannot change data (especially scalar functions).
- Can be called in SELECT, WHERE, or JOIN clauses.
- Used for calculations, formatting, or reusable logic.
DROP vs DELETE Statement
DROP:
- Removes the entire object (e.g., table, view, procedure) from the database.
- Deletes both the structure and data.
- Cannot be rolled back unless used within a transaction.
DELETE:
- Removes data from a table without deleting the table itself.
- Can use WHERE to delete specific rows.
- Can be rolled back if inside a transaction.
SELECT vs SELECT INTO
SELECT:
- Retrieves data from existing tables.
- Does not create new tables.
- Commonly used for viewing and filtering data.
SELECT INTO:
- Creates a new table based on selected columns and data.
- Copies both structure and data into the new table.
- Useful for backups or temporary storage.
DDL vs DML vs DCL vs DQL
DDL (Data Definition Language):
- Used to define and modify database structures.
- Commands: CREATE, ALTER, DROP, TRUNCATE.
DML (Data Manipulation Language):
- Used to manage data within tables.
- Commands: INSERT, UPDATE, DELETE.
DCL (Data Control Language):
- Used to control access and permissions.
- Commands: GRANT, REVOKE.
DQL (Data Query Language):
- Used to retrieve data from the database.
- Command: SELECT.
Table-Valued vs Multi-Statement Function
Table-Valued Function (Inline):
- Returns a table as the result of a single SELECT statement.
- Simple and efficient.
- Cannot use multiple statements or complex logic.
Multi-Statement Function:
- Returns a table but allows multiple statements inside the function.
- Supports variables, IF conditions, and loops.
- Slightly slower than inline due to complexity.
VARCHAR(50) vs VARCHAR(MAX)
VARCHAR(50):
- Stores up to 50 characters.
- More efficient for performance and storage when size is known.
- Common for short text fields like names or codes.
VARCHAR(MAX):
- Stores up to 2 GB of text data.
- Used for long text fields like articles or documents.
- Slower performance; use only when necessary.
SQL vs Windows Authentication
SQL Authentication:
- Uses a SQL Server username and password.
- Stored and managed inside SQL Server.
- Good for cross-platform or mixed environments.
Windows Authentication:
- Uses Windows user credentials (integrated login).
- More secure and managed by the Windows OS.
- Preferred in enterprise environments.
Inline Function vs View
Inline Function:
- Returns a table and accepts parameters.
- Used like a parameterized view.
- Offers flexibility and reusability.
View:
- A saved SELECT query that shows data like a virtual table.
- Cannot accept parameters.
- Used to simplify complex queries or secure data access.
Identity vs Unique Constraint
Identity:
- Auto-generates sequential numbers for a column.
- Common for primary keys.
- Only one identity column allowed per table.
Unique Constraint:
- Ensures all values in a column are different.
- Can be applied to any number of columns.
- Does not auto-generate values.