Skip to content

Commit b531a6e

Browse files
committed
added SQL intro
1 parent 8762a25 commit b531a6e

File tree

2 files changed

+106
-33
lines changed

2 files changed

+106
-33
lines changed

docs/sql/assets/01-sql-intro.png

177 KB
Loading

docs/sql/intro-sql.md

Lines changed: 106 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,76 @@ tags:
1717
description: In this tutorial, you will learn about SQL, its importance, what is SQL, why learn SQL, how to use SQL, steps to start using SQL, and more.
1818
---
1919

20-
SQL **Structured Query Language** is a standard programming language used to manage and manipulate relational databases. It allows users to store, retrieve, update, and delete data in a structured format.
20+
##
21+
SQL **Structured Query Language** is a standard programming language used to manage and manipulate relational databases. It allows users to store, retrieve, update, and delete data in a structured format. SQL became a standard of the American National Standards Institute (ANSI) in 1986 and of the International Organization for Standardization (ISO) in 1987.
2122

2223

2324
:::note
2425
Key Features of SQL:
2526
Data Querying: Retrieve data from one or more tables using commands like **SELECT**.
2627

27-
Data Manipulation: Add, update, or delete records using **INSERT**, **UPDATE**, and **DELETE**.
28+
DML (Data Manupulation Language): Add, update, or delete records using **INSERT**, **UPDATE**, and **DELETE**.
2829

29-
Data Definition: Define database structures using **CREATE**, **ALTER**, and **DROP**.
30+
DDL (Data Definition Language): Define database structures using **CREATE**, **ALTER**, and **DROP**.
3031

31-
Data Control: Control access and permissions with **GRANT** and **REVOKE**.
32+
DCL ( Data Control Language): Control access and permissions with **GRANT** and **REVOKE**.
33+
34+
TCL (Transactional Control Language): Involves **COMMIT** and **ROLLBACK**.
35+
:::
36+
37+
<BrowserWindow url="https://github.com" bodyStyle={{padding: 0}}>
38+
[![GitHub](./assets/01-sql-intro.png)](https://github.com/sanjay-kv)
39+
</BrowserWindow>
40+
41+
42+
43+
:::success
44+
Let's talk about history of Storing Data, It's started with physical files and shelf. Then later on company started using Excel or Access. There is limitation for these tools when comes to high data volume.
45+
46+
Then company started developing database management system like SQL, Postgres,MySQL.
47+
48+
> Databases are two types, SQL(Relational, Analytical OLAP) and NOSQL(key value, Graph, Document). This NoSQL provides more flexibility over Relational as it dont have to follow schemas.
49+
50+
> Schema is named collection of tables, which can contains, views, index, datatypes, operators and functions.
3251
:::
3352

34-
## What is SQL?
53+
:::info
3554

36-
SQL became a standard of the American National Standards Institute (ANSI) in 1986 and of the International Organization for Standardization (ISO) in 1987. SQL can execute queries against a database and retrieve data from it. It allows users to insert, update, and delete records in a database. Additionally, SQL can be used to create new databases and new tables within them. It also supports the creation of stored procedures, views, and the ability to set permissions on tables, procedures, and views.
55+
| **#** | **Keyword/Concept** | **Description** |
56+
|-------|--------------------------------------------------|---------------------------------------------------------------------------------|
57+
| 1 | `SELECT` | Retrieves data from one or more tables in a database. |
58+
| 2 | `FROM` | Specifies the table or tables to retrieve data from. |
59+
| 3 | `WHERE` | Filters rows based on specific conditions. |
60+
| 4 | `JOIN` | Combines rows from two or more tables based on a related column. |
61+
| 5 | `GROUP BY` | Groups rows that have the same values into summary rows. |
62+
| 6 | `ORDER BY` | Sorts the result-set by one or more columns. |
63+
| 7 | `HAVING` | Filters data after grouping using `GROUP BY`. |
64+
| 8 | `INSERT` | Adds new records to a table. |
65+
| 9 | `UPDATE` | Modifies existing records in a table. |
66+
| 10 | `DELETE` | Removes records from a table. |
67+
| 11 | `CREATE` | Creates a new database object (table, view, etc.). |
68+
| 12 | `ALTER` | Modifies an existing database object. |
69+
| 13 | `DROP` | Deletes a database object. |
70+
| 14 | Aggregation Functions (`MIN`, `MAX`, `AVG`, `COUNT`) | Performs calculations on a set of values and returns a single value. |
71+
| 15 | Joins (`INNER`, `LEFT`, `FULL`) | Retrieves data from multiple tables with matching or non-matching values. |
72+
| 16 | `CASE` Statement | Adds conditional logic within SQL queries. |
73+
| 17 | Window Functions (`RANK`, `DENSE_RANK`, `ROW_NUMBER`) | Performs calculations across a set of table rows related to the current row. |
3774

38-
:::info
3975

40-
1. **International Organization for Standardization (ISO)**:
41-
2. **American National Standards Institute (ANSI)**:
42-
3. Basic SQL Commands:
76+
1. **Structure and Content**: In SQL, the structure refers to how data is organized in tables, and the content refers to the actual data stored within those tables.
4377

44-
| Category | Command | Description |
45-
| --- | --------------- | -------------------- |
46-
| DQL (Query). | SELECT | Retrieve data from tables |
47-
| DML (Manipulation) | INSERT, UPDATE, DELETE | Modify table records |
48-
| DDL (Definition) | CREATE, ALTER, DROP | Define or change structure |
49-
| DCL (Control) | GRANT, REVOKE | Set permissions |
50-
| TCL (Transactions) | COMMIT, ROLLBACK | Manage transactions |
5178

52-
4. **Structure and Content**: In SQL, the structure refers to how data is organized in tables, and the content refers to the actual data stored within those tables.
79+
| **Category** | **Alias** | **Description** |
80+
|---------------|-----------|-----------------|
81+
| Tuple | Row | Record |
82+
| Attribute | Col | Field |
5383

54-
| Category | Alias | Description |
55-
| --- | --------------- | -------------------- |
56-
| Tuple | Row | Record |
57-
| Attribute | Col | Field|
5884

5985

6086
**For example, the following SAQl code creates a table named students**
6187

6288
<Tabs>
63-
<TabItem value="HTML">
89+
<TabItem value="Basic SQL">
6490
```sql
6591
-- Create a table
6692
CREATE TABLE Students (
@@ -96,20 +122,64 @@ SQL became a standard of the American National Standards Institute (ANSI) in 198
96122
(No rows returned)
97123
```
98124
</TabItem>
125+
<TabItem value="DDL">
126+
```sql
127+
-- CREATE TABLE statement to create a new table with columns and data types
128+
CREATE TABLE customers (
129+
id INT PRIMARY KEY,
130+
name VARCHAR(50),
131+
email VARCHAR(50));
132+
133+
-- ALTER TABLE statement to add a new column to an existing table
134+
ALTER TABLE customers ADD COLUMN phone VARCHAR(20);
135+
136+
-- DROP TABLE statement to remove a table from the database
137+
DROP TABLE customers;
138+
```
139+
</TabItem>
140+
<TabItem value="DML">
141+
```sql
142+
-- INSERT statement to add new data to a table
143+
INSERT INTO customers (name, email) VALUES ('John Doe', '[email protected]');
144+
145+
-- UPDATE statement to modify existing data in a table
146+
UPDATE customers SET email = '[email protected]' WHERE name = 'John Doe';
147+
148+
-- DELETE statement to remove data from a table
149+
DELETE FROM customers WHERE name = 'John Doe';
150+
```
151+
</TabItem>
152+
<TabItem value="DCL">
153+
```sql
154+
-- CREATE USER statement to create a new user account with specific permissions
155+
156+
CREATE USER 'new_user' IDENTIFIED BY 'password';
157+
GRANT SELECT, INSERT, UPDATE ON customers TO new_user;
158+
```
159+
</TabItem>
160+
<TabItem value="TCL">
161+
```sql
162+
-- BEGIN TRANSACTION statement to start a new transaction
163+
BEGIN TRANSACTION;
164+
165+
-- COMMIT statement to save changes made during a transaction
166+
COMMIT;
167+
168+
-- ROLLBACK statement to undo changes made during a transaction
169+
ROLLBACK;
170+
```
171+
</TabItem>
99172
</Tabs>
100173

101174

102-
5. **Platform Independent?**: Yes and No — It Depends. The core SQL language (based on ANSI/ISO standards) is platform-independent, meaning the basic syntax and concepts—like SELECT, INSERT, UPDATE, and DELETE—are the same across different database systems. ❌ But, SQL Implementations Are Not Fully Platform Independent:
175+
1. Advantages: **Platform Independent?**: Yes and No — It Depends. The core SQL language (based on ANSI/ISO standards) is platform-independent, meaning the basic syntax and concepts—like SELECT, INSERT, UPDATE, and DELETE—are the same across different database systems. ❌ But, SQL Implementations Are Not Fully Platform Independent:
176+
103177
Different Database Management Systems (DBMS)—like MySQL, PostgreSQL, Oracle, SQL Server, and SQLite—extend SQL differently. They may:
104178

105179
- Use different data types (VARCHAR vs TEXT, etc.)
106-
107180
- Have custom functions and features
108-
109181
- Handle stored procedures, triggers, and syntax differently
110-
111182
- Offer different tools and performance optimizations
112-
113183
- So, SQL code written for one system may not work exactly the same on another without adjustments.
114184

115185
:::
@@ -120,6 +190,12 @@ Different Database Management Systems (DBMS)—like MySQL, PostgreSQL, Oracle, S
120190

121191
**SQL (Structured Query Language)** is the standard language used to manage and query **relational databases** — the most common way data is stored across businesses. Whether it's **MySQL**, **PostgreSQL**, **SQL Server**, or **SQLite** — they all speak SQL! 💬
122192

193+
Data engineering is the process of collecting, transforming, and storing data in a way that allows for easy analysis and access. SQL is a critical tool in this process because it allows data engineers to:
194+
195+
1. ✅Retrieve data: SQL enables data engineers to retrieve specific data from a database by querying it based on certain criteria. This helps to ensure that data is accessible and easy to find.
196+
2. ✅Manipulate data: SQL also enables data engineers to manipulate data within a database by adding, deleting, or updating data. This helps to ensure that data is accurate and up-to-date.
197+
3. ✅Manage data: SQL enables data engineers to manage databases by creating tables, defining relationships between tables, and setting up security permissions. This helps to ensure that data is organized and secure.
198+
123199
---
124200

125201
## 📊 SQL: A Must-Have for Data-Driven Roles
@@ -141,15 +217,12 @@ From running ad-hoc queries to building pipelines and dashboards — SQL is ever
141217

142218
---
143219

144-
📌 *Master SQL to unlock the power of your data.*
145-
146-
147-
### Steps to start using HTML
220+
### Steps to start using SQL
148221

149222
**1. Set up your development environment**: Go to MySQL Downloads Page:
150223
- Visit MySQL Workbench Downloads.
151224

152-
**2. Download the Installer:**: To create your first HTML document, follow these steps:
225+
**2. Download the Installer:**: To create your first SQL commands, follow these steps:
153226

154227
- Select the version compatible with your operating system (Windows, macOS, or Linux).
155228
- Click Download and follow the installation instructions.

0 commit comments

Comments
 (0)