SQL_FINAL_NOTES
SQL_FINAL_NOTES
Data models
Logical: Defines the structure and constraints without detailing physical implementation.
NOTE:
NCHAR: Uses 2 bytes per character (fixed length). 2 bytes rest same as CHAR.
Miscellaneous Knowledge:
JWT TOKENS
JWT tokens are compact, URL-safe tokens used for securely transmitting information
between parties, consisting of three parts: a header, a payload, and a signature.
Header
Payload
Signature
SQL Server: A Relational Database Management System (RDBMS) that is used to store,
retrieve, and manage data.
OLTP (Online Transaction Processing): Focuses on real-time processing of transactional
data.
SQL server: RDBMS and is used for store, retrieve, manage data
Used in data warehouses for analysis and reporting purposes, denormalization removes
the need for frequent CRUD operations.
Aliases
Used to rename a column or table for readability.
CASE Statement
Joins
LEFT JOIN: Returns all records from the left table and matching ones from the right.
SELECT A.column1, B.column2 FROM TableA A
LEFT JOIN TableB B ON A.common_column = B.common_column;
RIGHT JOIN: Returns all records from the right table and matching ones from the left.
FULL OUTER JOIN: Returns all records when there is a match in either table.
Set Operations
EXCEPT: Returns records from the first query that are not in the second.
Temporary Tables
Temporary tables store data temporarily for a session, ensuring the correct data is fetched
and manipulated for each call.
Syntax:
Types:
Local Temporary Tables (#table_name): Available only within the current session.
Views
Views allow querying of data without modifying the original table structure.
Key Points:
Managing Views:
Stored Procedures
Syntax:
Triggers
Types:
Example Trigger:
Grant Permission:
Revoke Permission:
Types:
Clustered Index
Non-clustered Index
Example:
Performance Calculation:
String Functions
String Functions
LEFT(): Returns the left part of a string with a specified number of characters.
RIGHT(): Returns the right part of a string with a specified number of characters.
STUFF(): Deletes a part of a string and inserts another string at a specified position.
Denormalization
ETL (Extract, Transform, Load) is used to move data into a target system.
KEY DIFFERENCES: