0% found this document useful (0 votes)
2 views3 pages

Learn SQL: Know Everything About SQL

This document is a comprehensive guide to SQL, covering various topics such as getting started, ALTER TABLE commands, logical operators, cascading deletes, and the use of CASE statements. It includes syntax explanations, examples, and best practices for writing clean SQL code. Additionally, it discusses comments and common table expressions, providing a thorough understanding of SQL functionalities.
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)
2 views3 pages

Learn SQL: Know Everything About SQL

This document is a comprehensive guide to SQL, covering various topics such as getting started, ALTER TABLE commands, logical operators, cascading deletes, and the use of CASE statements. It includes syntax explanations, examples, and best practices for writing clean SQL code. Additionally, it discusses comments and common table expressions, providing a thorough understanding of SQL functionalities.
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

LEARN SQL

Know Everything About SQL


Table of Contents
About 1
Chapter 1: Getting started with SQL 2
Remarks 2

Versions 2

Examples 2
2
Overview
4
Chapter 2: ALTER TABLE 4
Introduction 4
Syntax 4
Examples 4

Add Column(s) 4

Drop Column 4

Drop Constraint 4

Add Constraint 5

Alter Column 5
6
Add Primary Key
6
Chapter 3: AND & OR Operators
6
Syntax
6
Examples 7
7
AND OR Example 7
Chapter 4: Cascading Delete 9
9
Examples
9
ON DELETE CASCADE
9
Chapter 5: CASE
9
Introduction
9
Syntax
10
Remarks

Examples

Searched CASE in SELECT (Matches a boolean expression)

Use CASE to COUNT the number of rows in a column match a condition.


Shorthand CASE in SELECT 11

CASE in a clause ORDER BY 11

Using CASE in UPDATE 12

CASE use for NULL values ordered last 12

CASE in ORDER BY clause to sort records by lowest value of 2 columns 13

Sample data 13

Query 13

Results 14

Explanation 14

Chapter 6: Clean Code in SQL 15

Introduction 15

Examples 15
15
Formatting and Spelling of Keywords and Names
15
Table/Column Names
15
Keywords
15
SELECT *
16
Indenting
17
Joins
19
Chapter 7: Comments 19
19
Examples
19
Single-line comments
20
Multi-line comments 20
Chapter 8: Common Table Expressions 20
Syntax 20
Remarks 20
Examples 21

Temporary query 21

recursively going up in a tree 22

generating values 23

recursively enumerating a subtree

Oracle CONNECT BY functionality with recursive CTEs

You might also like