0% found this document useful (0 votes)
5 views

SQL Cheat Sheet

This SQL Cheat Sheet provides key SQL keywords and their meanings, organized into categories such as Data Querying, Joins, Data Definition, Data Manipulation, and Data Control. It includes examples for each keyword to aid in understanding and revision. The document also lists various functions for aggregate, string, and date manipulations.

Uploaded by

tawedivine2
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)
5 views

SQL Cheat Sheet

This SQL Cheat Sheet provides key SQL keywords and their meanings, organized into categories such as Data Querying, Joins, Data Definition, Data Manipulation, and Data Control. It includes examples for each keyword to aid in understanding and revision. The document also lists various functions for aggregate, string, and date manipulations.

Uploaded by

tawedivine2
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/ 1

Absolutely!

Here's a concise SQL Cheat Sheet with key keywords and their meanings, great for exam
revision:

🗄️ SQL Cheat Sheet: Keywords & Meanings


📊 Data Querying
`SELECT`: Retrieves data from a database.
Example: `SELECT * FROM students;`
`FROM`: Specifies the table to query.
Example: `SELECT name FROM employees;`

`WHERE`: Filters records based on conditions.


Example: `SELECT * FROM products WHERE price > 100;`
`AND`, `OR`, `NOT`: Logical operators in conditions.
Example: `WHERE age > 18 AND status = 'active'`
`ORDER BY`: Sorts result (ASC or DESC).
Example: `ORDER BY name ASC;`
`GROUP BY`: Groups rows with the same values.
Example: `SELECT dept, COUNT(*) FROM staff GROUP BY dept;`
`HAVING`: Filters groups after `GROUP BY`.
Example: `HAVING COUNT(*) > 5`

`LIMIT` / `TOP`: Limits the number of rows returned.


Example: `SELECT * FROM students LIMIT 10;`

🔄 Joins
`INNER JOIN`: Matches records in both tables.
`LEFT JOIN`: All records from left, matched from right.
`RIGHT JOIN`: All from right, matched from left.
`FULL JOIN`: All records when there's a match in either table.

🧱 Data Definition (DDL)


`CREATE TABLE`: Creates a new table.
Example: `CREATE TABLE users (id INT, name VARCHAR(50));`
`ALTER TABLE`: Modifies a table (add/drop column).
Example: `ALTER TABLE users ADD email VARCHAR(100);`
`DROP TABLE`: Deletes a table and its data.
`TRUNCATE TABLE`: Deletes all rows, keeps table structure.

✏️ Data Manipulation (DML)


`INSERT INTO`: Adds new data.
Example: `INSERT INTO users (id, name) VALUES (1, 'Alice');`
`UPDATE`: Modifies existing data.

Example: `UPDATE users SET name = 'Bob' WHERE id = 1;`


`DELETE`: Deletes data.
Example: `DELETE FROM users WHERE id = 1;`

🔐 Data Control & Others


`CREATE INDEX`: Speeds up searches.

`PRIMARY KEY`: Unique identifier for table rows.


`FOREIGN KEY`: Ensures referential integrity.
`UNIQUE`: Column must have unique values.
`CHECK`: Ensures column value meets a condition.
`DEFAULT`: Sets a default value.
`NULL`: Represents missing/unknown value.
`IS NULL / IS NOT NULL`: Checks for null values.

📐 Functions
Aggregate: `COUNT()`, `SUM()`, `AVG()`, `MIN()`, `MAX()`
String: `UPPER()`, `LOWER()`, `LENGTH()`, `SUBSTRING()`
Date: `NOW()`, `CURDATE()`, `DATEDIFF()`

Would you like this formatted as a printable PDF or image for easier revision?

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/1

You might also like