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

SQL Database Cheat Sheet

This cheat sheet outlines essential SQL and database concepts, including CRUD operations, stored procedures, views, and joins. It also covers backup and restore procedures, security measures, indexing, and normalization techniques. Additionally, it highlights advanced topics such as window functions, triggers, and table types.

Uploaded by

legendkiller5578
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)
1 views2 pages

SQL Database Cheat Sheet

This cheat sheet outlines essential SQL and database concepts, including CRUD operations, stored procedures, views, and joins. It also covers backup and restore procedures, security measures, indexing, and normalization techniques. Additionally, it highlights advanced topics such as window functions, triggers, and table types.

Uploaded by

legendkiller5578
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 & Database Concepts Cheat Sheet

1. CRUD Operations
CREATE: Add new records
READ (SELECT): Fetch data
UPDATE: Modify existing records
DELETE: Remove records

2. Stored Procedures
Reusable SQL blocks stored in the database. Can accept parameters and return values.

3. Views
Virtual tables based on SELECT queries. Used for abstraction and security.

4. Pagination
Used to split results into pages. Example:
SELECT * FROM Table ORDER BY ID OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

5. Joins
INNER JOIN: Matching rows
LEFT JOIN: All from left + matches from right
RIGHT JOIN: All from right + matches from left
FULL JOIN: All from both
CROSS JOIN: Cartesian product

6. Set Operations
UNION: Combine and remove duplicates
UNION ALL: Combine with duplicates
INTERSECT: Common rows
EXCEPT: Rows in first but not second

7. Backup & Restore


BACKUP DATABASE dbname TO DISK='path.bak'
RESTORE DATABASE dbname FROM DISK='path.bak'

8. Security
GRANT/REVOKE permissions
Use roles, users, and parameterized queries to avoid SQL injection

9. Indexes
SQL & Database Concepts Cheat Sheet

Speed up searches but slow down write operations

10. CTE & Subqueries


CTE: WITH temp AS (...)
Subqueries: Queries inside other queries

11. Window Functions


ROW_NUMBER(), RANK(), LEAD(), LAG() - used in analytics

12. Triggers
Automatic procedures after INSERT/UPDATE/DELETE

13. Table Types


Temp Tables: #Temp
Table Variables: DECLARE @temp TABLE (...)

14. Constraints
PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, DEFAULT, NOT NULL

15. Normalization
Organize data to reduce redundancy and improve integrity

You might also like