SQL BASIC
.
๐ง Part 1: Introduction to SQL (Structured Query Language)
๐ก What is SQL?
SQL (Structured Query Language) is the standard programming language used to manage and manipulate relational databases. With SQL, you can:
-
Create and modify database structures (schemas)
-
Insert, update, delete, and retrieve data
-
Control access to data (via permissions)
-
Analyze data using aggregation and filtering
SQL works with relational database systems like:
-
MySQL
-
PostgreSQL
-
SQLite
-
SQL Server
-
Oracle
SQL commands are grouped into five major categories:
| Category | Description | Example |
|---|---|---|
| DDL (Data Definition Language) | Defines database structure | CREATE, ALTER, DROP |
| DML (Data Manipulation Language) | Deals with data modification | INSERT, UPDATE, DELETE |
| DQL (Data Query Language) | Fetches data | SELECT |
| TCL (Transaction Control Language) | Manages transactions | COMMIT, ROLLBACK |
| DCL (Data Control Language) | Manages access rights | GRANT, REVOKE |
Part 2: Data Definition Language (DDL)
๐ธ 1. CREATE Statement
Used to create databases, tables, views, indexes, etc.
>> Syntax
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
๐ Example:
๐ธ 2. ALTER Statement:
Modifies an existing table structure.
✅ Syntax:
๐ Example:
๐งฑ Part 3: Data Manipulation Language (DML)
๐ธ 1. INSERT INTO
Adds new data into a table.
✅ Syntax:
๐ Example:
๐ธ 2. UPDATE
Modifies existing records in the table
✅ Syntax:
๐ Example
NOTE: Always use WHERE to avoid updating all rows by mistake.
๐ธ 3. DELETE
Removes records from a table but the Structured of the table will remain same.
๐ Example:
๐ Part 4: Data Query Language (DQL)
๐ธ SELECT Statement
Used to retrieve data from a table.
✅ Syntax:
๐ Example:
Comments
Post a Comment