-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.Getting Started with SQL.sql
More file actions
192 lines (143 loc) · 3.46 KB
/
0.Getting Started with SQL.sql
File metadata and controls
192 lines (143 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
=========================================================
Getting Started With SQL
Introduction to SQL and Relational Databases
=========================================================
SQL (Structured Query Language) is the standard language
used to interact with relational databases.
It allows you to:
- Retrieve data
- Insert new data
- Update existing data
- Delete data
- Create and manage database structures
SQL is used by:
- Data Analysts
- Data Engineers
- Backend Developers
- Database Administrators
- Data Scientists
Examples of database systems that use SQL:
- MySQL
- PostgreSQL
- SQL Server
- Oracle
- SQLite
=========================================================
Basic Database Concepts
=========================================================
DATABASE
A database is an organized collection of structured data.
Example:
A school database might store:
- students
- teachers
- classes
- grades
SCHEMA
A schema is a logical container that holds tables,
views, and other database objects.
Example:
CREATE SCHEMA school_db;
TABLE
A table stores data in rows and columns.
Example table structure:
students
---------------------------------
id | student_name | grade_level
---------------------------------
COLUMN
A column represents a single attribute of the data.
Examples:
student_name
email
birthday
ROW (RECORD)
A row represents one record in the table.
Example row:
1 | Abby Johnson | 10
PRIMARY KEY
A primary key uniquely identifies each row in a table.
Example:
id INT PRIMARY KEY
=========================================================
Understanding Relational Databases
=========================================================
A relational database organizes data into multiple
tables that are related to each other.
Relationships between tables are created using keys.
Example:
students table
----------------------
id | student_name
student_grades table
----------------------
student_id | class | grade
Here:
student_grades.student_id references students.id
This allows us to connect information between tables.
Benefits of relational databases:
- Organized data structure
- Reduced data duplication
- Easier data analysis
- Ability to combine data from multiple tables
=========================================================
Writing and Executing Queries
=========================================================
A QUERY is a request for data from a database.
The most common SQL statement is SELECT.
Example: Retrieve all data from a table
*/
SELECT * FROM students;
/*
SELECT specifies which columns you want.
Example: Retrieve specific columns
*/
SELECT student_name, grade_level
FROM students;
/*
Filtering results using WHERE
*/
SELECT *
FROM students
WHERE grade_level = 10;
/*
Using comparison operators
*/
SELECT *
FROM students
WHERE gpa > 3.5;
/*
Using logical operators
*/
SELECT *
FROM students
WHERE grade_level = 11
AND gpa > 3.0;
/*
Sorting results
*/
SELECT *
FROM students
ORDER BY gpa DESC;
/*
Limiting results
*/
SELECT *
FROM students
LIMIT 5;
/*
=========================================================
Summary
=========================================================
SQL is used to interact with relational databases.
Key concepts learned:
- Databases store structured data
- Tables contain rows and columns
- Primary keys uniquely identify rows
- Queries retrieve and manipulate data
- SELECT is the most commonly used SQL statement
Next step:
Learn how SELECT, FROM, and WHERE work together
to filter and retrieve data efficiently.
*/