Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

SQL Cheat Sheet Expanded

This document provides a cheat sheet for SQL, covering basic commands, data types, filtering data, aggregate functions, joins, indexes and constraints, transactions, and stored procedures. It includes examples for each section to illustrate usage. The cheat sheet serves as a quick reference for SQL syntax and operations.

Uploaded by

raghubirkar11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL Cheat Sheet Expanded

This document provides a cheat sheet for SQL, covering basic commands, data types, filtering data, aggregate functions, joins, indexes and constraints, transactions, and stored procedures. It includes examples for each section to illustrate usage. The cheat sheet serves as a quick reference for SQL syntax and operations.

Uploaded by

raghubirkar11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Cheat Sheet

SQL Cheat Sheet

1. Basic SQL Commands

SELECT * FROM table_name; -- Select all records


INSERT INTO table_name (column1, column2) VALUES (value1, value2); -- Insert data
UPDATE table_name SET column1 = value1 WHERE condition; -- Update data
DELETE FROM table_name WHERE condition; -- Delete records

2. Data Types

INT - Integer
VARCHAR(n) - String with max length n
TEXT - Large text data
DATE - Date format
DECIMAL(p,s) - Fixed-point number
BOOLEAN - True/False

3. Filtering Data

SELECT * FROM table_name WHERE column1 = 'value';


SELECT * FROM table_name WHERE column1 LIKE '%pattern%';
SELECT * FROM table_name WHERE column1 BETWEEN value1 AND value2;

4. Aggregate Functions

SELECT COUNT(*) FROM table_name;


SELECT SUM(column1) FROM table_name;
SELECT AVG(column1) FROM table_name;
SELECT MAX(column1) FROM table_name;
SELECT MIN(column1) FROM table_name;

5. Joins

SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;


Java Cheat Sheet

SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;


SELECT * FROM table1 RIGHT JOIN table2 ON table1.id = table2.id;

6. Indexes & Constraints

CREATE INDEX idx_name ON table_name(column1);


ALTER TABLE table_name ADD CONSTRAINT unique_name UNIQUE (column1);
ALTER TABLE table_name ADD FOREIGN KEY (column1) REFERENCES other_table(column2);

7. Transactions

BEGIN TRANSACTION;
UPDATE table_name SET column1 = value1 WHERE condition;
COMMIT;

8. Stored Procedures

CREATE PROCEDURE procedure_name AS BEGIN


SELECT * FROM table_name;
END;

You might also like