0% found this document useful (0 votes)
3 views4 pages

Complete SQL Guide

The document is a comprehensive guide to SQL queries, covering essential commands such as SELECT, INSERT, UPDATE, DELETE, and table management commands like CREATE, ALTER, and DROP. It also discusses advanced concepts like JOIN, GROUP BY, HAVING, and optimization techniques for improving query performance. Additionally, it touches on normalization and denormalization processes for data organization and integrity.

Uploaded by

dharialokesh11
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)
3 views4 pages

Complete SQL Guide

The document is a comprehensive guide to SQL queries, covering essential commands such as SELECT, INSERT, UPDATE, DELETE, and table management commands like CREATE, ALTER, and DROP. It also discusses advanced concepts like JOIN, GROUP BY, HAVING, and optimization techniques for improving query performance. Additionally, it touches on normalization and denormalization processes for data organization and integrity.

Uploaded by

dharialokesh11
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/ 4

Complete SQL Query Guide

1. SELECT Query

SELECT column1, column2, ...

FROM table_name;

2. INSERT Query

INSERT INTO table_name (column1, column2, ...)

VALUES (value1, value2, ...);

3. UPDATE Query

UPDATE table_name

SET column1 = value1, column2 = value2, ...

WHERE condition;

4. DELETE Query

DELETE FROM table_name WHERE condition;

5. CREATE TABLE Query

CREATE TABLE table_name (

column1 datatype,

column2 datatype,

...);

6. ALTER TABLE Query

ALTER TABLE table_name

ADD column_name datatype;

7. DROP TABLE Query

DROP TABLE table_name;


8. JOIN Query

SELECT columns

FROM table1

JOIN table2 ON table1.id = table2.id;

9. GROUP BY Query

SELECT column1, COUNT(*)

FROM table_name

GROUP BY column1;

10. HAVING Query

SELECT column1, COUNT(*)

FROM table_name

GROUP BY column1

HAVING COUNT(*) > 5;

11. ORDER BY Query

SELECT column1, column2

FROM table_name

ORDER BY column1 DESC;

12. DISTINCT Query

SELECT DISTINCT column1

FROM table_name;

13. UNION Query

SELECT column1 FROM table1

UNION

SELECT column1 FROM table2;


14. WHERE Clause

SELECT column1

FROM table_name

WHERE column1 = value;

15. LIKE Clause

SELECT column1

FROM table_name

WHERE column1 LIKE 'A%';

16. IN Clause

SELECT column1

FROM table_name

WHERE column1 IN (value1, value2, ...);

17. Views

CREATE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;

18. Normalization

Normalization involves organizing data to reduce redundancy and ensure data integrity.

- 1NF: Atomic values

- 2NF: Remove partial dependency

- 3NF: Remove transitive dependency

19. Denormalization

Denormalization is the process of adding redundancy back into a database to improve read
performance at the cost of some data integrity.

Example: Combine multiple tables into one to avoid joins for frequently queried data.

20. SQL Optimization

Optimization involves improving query performance by using techniques like:

- Use indexes

- Avoid SELECT *

- Optimize joins

- Limit the result set

- Use EXISTS instead of IN

- Avoid complex subqueries

You might also like