{"id":23073720,"url":"https://github.com/akashdip2001/sql-study-notes","last_synced_at":"2025-04-30T08:13:03.572Z","repository":{"id":259610555,"uuid":"879043943","full_name":"akashdip2001/SQL-study-notes","owner":"akashdip2001","description":"Study Notes for SQL, RDBMS","archived":false,"fork":false,"pushed_at":"2024-11-02T20:47:10.000Z","size":16337,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T08:12:49.875Z","etag":null,"topics":["database","dbms","notes","rdbms","sql","sql-server","study-notes"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akashdip2001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-26T20:08:28.000Z","updated_at":"2025-04-11T13:51:48.000Z","dependencies_parsed_at":"2025-02-09T00:45:01.363Z","dependency_job_id":"928cb699-2a7f-448d-8b54-4c33725f3a9b","html_url":"https://github.com/akashdip2001/SQL-study-notes","commit_stats":null,"previous_names":["akashdip2001/sql-study-notes-"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FSQL-study-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FSQL-study-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FSQL-study-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akashdip2001%2FSQL-study-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akashdip2001","download_url":"https://codeload.github.com/akashdip2001/SQL-study-notes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666338,"owners_count":21624295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dbms","notes","rdbms","sql","sql-server","study-notes"],"created_at":"2024-12-16T08:18:47.549Z","updated_at":"2025-04-30T08:13:03.550Z","avatar_url":"https://github.com/akashdip2001.png","language":null,"readme":"# Iintroduction Contents\n\n1. [What is Data ?](#What-is-Data)\n2. [What is DataBase ?](#What-is-DataBase)\n3. [Data store technique](#Data-store-technique)\n4. [Database Types](#Database-Types)\n5. [SQL vs MySQL](#SQL-vs-MySQL)\n6. [Download SQL](#Download)\n7. [ANSI SQL Study Notes](#ANSI-SQL-Study-Notes) ✅\n8. [**practical**](#practical) \n9. [**EXAM**](#EXAM) ✅✅\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n# What is Data\n\nData is a collection of raw facts. \n#### Example: \nNumber, text, etc.\n\n# What is DataBase\nAn Organised collection of structured data, that is stored access \u0026 manipulate electronically to manage efficiently called DataBase.\n\nExample:\n\n| F Name | L Name | City | Contact |\n|:---:|:---:|:---:|:---:|\n| AKashdip | Mahapatra | Haldia | 70xxxxxxxx |\n| Rahul | Das | London | 7894561237 |\n\n---\n\n# Data store technique\n```yaml\nData store technique\n│\n├── Books \u0026 file System\n│── Flat file System: Notepad in pc\n└── Database\n```\n\n|  | Books \u0026 file System | Flat file System |  | Database |\n|---|---|---|---|---|\n| Maintenance problam | ❌ | ❌ | | ✅ |\n| Security Problam | ❌ | ❌ | | ✅ |\n| Required more Man power | ✅ | ⚠️ | | ❌ |\n| Costly in maintenance | ✅ | ⚠️ | | ❌ |\n| Retrieve | ❌ | ❌ (No indexing) | | ✅ |\n| Backup | ❌ | ✅ | | ✅ |\n| easy Editing | ❌ | ✅ | | ✅ |\n| Remote access | ❌ | ✅ | | ✅ |\n| Share \u0026 Carry data | ❌ | ✅ | | ✅ |\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n| ✅ [**Skip to Main Topic**](#ANSI-SQL-Study-Notes) ➡️ |\n|---|\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n# Database Types\n\n| **Database Type**             | **Characteristics**                                                                                   | **Examples**                                    |\n|--------------------------------|------------------------------------------------------------------------------------------------------|--------------------------------------------------|\n| | |\n| **Relational Databases (RDBMS)** | Use tables (rows and columns), enforce ACID properties, support SQL for querying data.               | MySQL, PostgreSQL, Oracle, SQL Server, SQLite    |\n| | |\n| **NoSQL Databases**           | Schema-less, handle unstructured or semi-structured data, ideal for distributed systems.             | MongoDB, Cassandra, DynamoDB, Redis, Couchbase   |\n| | |\n| - **Key-Value Stores**        | Data stored as key-value pairs, highly performant for simple read/write operations.                  | Redis, DynamoDB, Riak, Memcached                 |\n| | |\n| - **Document Stores**         | Store data in JSON-like documents, flexible and often used in web apps.                             | MongoDB, Couchbase, Firebase Firestore           |\n| | |\n| - **Column-Family Stores**    | Data organized in columns, efficient for analytical and large-scale data applications.              | Cassandra, HBase, Google Bigtable                |\n| | |\n| - **Graph Databases**         | Optimized for handling and querying data with complex relationships (e.g., social networks).        | Neo4j, Amazon Neptune, ArangoDB, OrientDB       |\n| | |\n| **Object-Oriented Databases (OODBMS)** | Store data as objects, similar to objects in programming languages like Java or C#.               | db4o, ObjectDB, Versant Object Database          |\n| | |\n| **Time-Series Databases (TSDB)** | Optimized for time-stamped data (e.g., metrics, logs, and IoT data).                               | InfluxDB, Prometheus, TimescaleDB                |\n| | |\n| **Graph Databases**           | Store data in nodes and edges, ideal for applications involving connections and networks.           | Neo4j, Amazon Neptune, ArangoDB                  |\n| | |\n| **Columnar Databases**        | Store data in columns rather than rows, optimized for analytics and data warehousing.               | Apache HBase, Amazon Redshift, Google Bigtable   |\n| | |\n| **In-Memory Databases**       | Data stored in-memory for fast access, suitable for real-time applications.                         | Redis, Memcached, SAP HANA                       |\n| | |\n| **NewSQL Databases**          | Combine SQL with NoSQL scalability, maintaining ACID compliance for distributed systems.            | CockroachDB, Google Spanner, VoltDB              |\n| | |\n| **Embedded Databases**        | Lightweight databases embedded within applications, often file-based.                              | SQLite, LevelDB, Berkeley DB                     |\n| | |\n| **Multimodel Databases**      | Support multiple data models (e.g., document, graph, key-value) within a single system.            | ArangoDB, OrientDB, Couchbase                    |\n\n---\n\n# SQL vs MySQL\n\n| **SQL** | **MySQL** |\n| --- | --- |\n| Structured Query Language, used to talk (access \u0026 Changes) to our DB | DBMS which uses SQL to talk with DB |\n\n---\n\n# Download\n## ✈️ [Link for Windows](https://dev.mysql.com/downloads/installer/)\n## ✈️ [for Linux](https://drive.google.com/file/d/1coREmAmIW34bkyvbZPbR71dONkX0Z8Qv/view?usp=drivesdk)\n\u003c/br\u003e\n\u003cdiv style=\"display: flex; justify-content: space-around;\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/00faaac0-1b47-482a-a777-f80e2cc339f8\" alt=\"python projects\" style=\"width: 45%; height: auto;\"/\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/ebd6157f-fd11-4273-b007-cc5ddce31486\" alt=\"pythonprojects\" style=\"width: 45%; height: auto;\"/\u003e\n\u003c/div\u003e\n\n---\n\u003c/br\u003e\n\n### GUI \u0026 CLI\n\u003cimg align=\"right\" alt=\"DBMS\" width=\"550\" src=\"https://github.com/user-attachments/assets/02928922-231e-4441-bacc-9f7592b4bda0\"\u003e\n\n#### You can use SQL with `Workbanch` or `CLI mode` (case sensitive)\n```sql\nSHOW DATABASES;\n```\nOutput\n```go\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n| sakila             |\n| sys                |\n| world              |\n+--------------------+\n```\n---\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n# ANSI SQL Study Notes\n### Table of Contents\n1. [Introduction to Databases](#introduction-to-databases)\n2. [DBMS vs. RDBMS](#dbms-vs-rdbms)\n    - [RDBMS Terms](#RDBMS-Terms)\n    - [RDBMS Relationship](#RDBMS-Relationship)\n    - [Schema](#schema)\n    - [Key](#key)\n    - [ER Model](#er-model)\n3. [SQL Basics](#sql-basics)\n4. [Data Definition Language (DDL)](#ddl)\n5. [Data Manipulation Language (DML)](#dml)\n6. [Data Control Language (DCL)](#dcl)\n7. [Transaction Control Language (TCL)](#tcl)\n8. [Constraints and Their Types](#constraints)\n9. [SQL Operators](#sql-operators)\n10. [SQL Functions](#sql-functions)\n11. [SQL Clauses](#sql-clauses)\n12. [Joins and Their Types](#joins)\n13. [Subqueries](#subqueries)\n14. [Views](#views)\n15. [Indexes](#indexes)\n16. [**practical**](#practical)\n17. [**EXAM**](#EXAM)\n\n---\n[\u003cimg align=\"right\" alt=\"DBMS\" width=\"400\" src=\"https://github.com/user-attachments/assets/1d5e3c49-1a80-4f03-8585-247338cd45ab\"\u003e](https://youtu.be/Hy3qbMAoEJk)\n\n## 1. Introduction to Databases \u003ca name=\"introduction-to-databases\"\u003e\u003c/a\u003e\n\nA **database** is an organized collection of data that can be accessed, managed, and updated. It is often used to store large volumes of information for easy retrieval, analysis, and manipulation.\n\n**Example:** \nImagine a company’s employee database, which stores information like employee names, IDs, departments, and salaries.\n\n---\n\n## 2. DBMS vs. RDBMS \u003ca name=\"dbms-vs-rdbms\"\u003e\u003c/a\u003e\n\n```yaml\nDBMS\n│\n├── RDBMS: (Data store in Row \u0026 Column format --\u003e Table)\n│\n│── No SQL DBMS: Unstructured format data  \n│   │──\u003e Mongo DB\n│   └──\u003e Redis\n│\n│── HDBMS: Hierarchical DBMS (Tree)\n│   └──\u003e IMS (IBM launched 1st HDBMS Softwer IMS in 1960)\n│\n│── NDBMS: Netwirk DBMS (data in Graphical Structure) all nodes are diractly connected.\n│   └──\u003e IDS (Codasyl,IDS,1964)\n│\n└── OODBMS: Object Orianted DBMS\n```\n\n**DBMS (Database Management System):**\n- Software for creating, retrieving, updating, and managing data in databases.\n- Supports a variety of database models like hierarchical, network, and object-oriented models.\n\n**RDBMS (Relational Database Management System):**\n\n- Store imformation in `Table` form\n- A type of DBMS specifically designed for relational databases.\n- Data is stored in tables and can be related based on key values.\n\n| Feature                        | DBMS (Database Management System)                                     | RDBMS (Relational Database Management System)                      |\n|--------------------------------|----------------------------------------------------------------------|-------------------------------------------------------------------|\n| | |\n| **Data Structure**             | Data can be organized in hierarchical, network, or object-oriented formats. | Data is always organized in tables (rows and columns).            |\n| | |\n| **Relationships**              | Generally does not support relationships between data elements.     | Supports relationships through primary and foreign keys.          |\n| | |\n| **Data Integrity**             | Limited enforcement of data integrity constraints.                  | Enforces data integrity using ACID (Atomicity, Consistency, Isolation, Durability) properties. |\n| | |\n| **Data Redundancy**            | Higher likelihood of data redundancy due to lack of relational structures. | Reduced redundancy due to normalization in relational tables.     |\n| | |\n| **Examples**                   | Hierarchical DBMS, Network DBMS, Object-Oriented DBMS               | MySQL, PostgreSQL, Oracle, Microsoft SQL Server                   |\n| | |\n| **Example Syntax (Insert)**    | `ADD NODE 'Employee' UNDER 'Department'`                             | `INSERT INTO Employees (EmployeeID, Name) VALUES ('E001', 'Alice');` |\n| | |\n| **Example Syntax (Retrieve)**  | `FIND NODE 'Employee' UNDER 'Department: Sales'`                    | `SELECT Name FROM Employees WHERE DepartmentID = 1;`              |\n| | |\n| **Scalability**                | Suitable for small to medium-sized applications.                    | Designed to handle larger applications and complex data needs.    |\n| | |\n| **Multi-user Access**          | Limited support for multi-user access.                              | Strong support for multi-user access and concurrency control.     |\n\n---\n\nLet's break down the difference between **DBMS** and **RDBMS** by showing a concrete example with clear structures to illustrate how data might be organized in each.\n\n### ✅. DBMS Example (Hierarchical DBMS)\nIn a **Hierarchical DBMS**, data is stored in a tree-like structure, similar to a folder system, where each piece of data (called a **node**) is connected in a parent-child relationship.\n\n#### Scenario:\nImagine we have data for **Departments** and **Employees** where each department has employees.\n\n#### Structure:\n```yaml\nDepartment (root node)\n│\n├── Department: Sales\n│   ├── Employee: Alice\n│   └── Employee: Bob\n│\n└── Department: HR\n    ├── Employee: Carol\n    └── Employee: Dave\n```\n\n#### Example Syntax (Hierarchical DBMS):\n1. **To add a new employee under a department (e.g., adding Eve in Sales):**\n   ```sql\n   ADD NODE 'Employee' UNDER 'Department: Sales' SET Attributes(Name=\"Eve\", ID=\"E002\")\n   ```\n\n2. **To retrieve all employees in a department (e.g., Sales):**\n   ```sql\n   FIND NODE 'Employee' UNDER 'Department: Sales'\n   ```\n\nIn this DBMS, there are no **tables**. Data is organized in a tree, and you access nodes by navigating through the hierarchy.\n\n---\n\n### ✅. RDBMS Example (Relational DBMS)\nIn an **RDBMS**, data is stored in tables with rows and columns, where tables can relate to each other through keys (e.g., primary keys and foreign keys).\n\n#### Scenario:\nWe'll use the same **Departments** and **Employees** data, but here they are stored in tables that relate to each other.\n\n#### Structure:\n- **Departments Table**\n  | DepartmentID | DepartmentName |\n  |--------------|----------------|\n  | 1            | Sales          |\n  | 2            | HR             |\n\n- **Employees Table**\n  | EmployeeID | Name  | DepartmentID |\n  |------------|-------|--------------|\n  | E001       | Alice | 1            |\n  | E002       | Bob   | 1            |\n  | E003       | Carol | 2            |\n  | E004       | Dave  | 2            |\n\nHere, the **DepartmentID** in the **Employees Table** acts as a foreign key that links to the **Departments Table**.\n\n#### Example Syntax (RDBMS):\n1. **To add a new employee to the Sales department:**\n   ```sql\n   INSERT INTO Employees (EmployeeID, Name, DepartmentID) VALUES ('E005', 'Eve', 1);\n   ```\n\n2. **To retrieve all employees in the Sales department:**\n   ```sql\n   SELECT Name FROM Employees WHERE DepartmentID = 1;\n   ```\n\nIn an **RDBMS**, data is stored in a **tabular form** with relationships between tables, unlike DBMS, where data could be stored hierarchically or in other non-tabular structures.\n\n## RDBMS Terms \u003ca name=\"RDBMS-Terms\"\u003e\u003c/a\u003e\n\u003cimg align=\"right\" alt=\"python_logo\" width=\"600\" src=\"https://github.com/user-attachments/assets/f80968aa-7a43-4028-8c44-6552c7185ac4\"\u003e \n\n```yaml\nRDBMS Terms\n│\n│── Entity (Table)\n│── Attribute (Column)\n│── Records (Row)\n│── Degree (No. of Column)\n│── Cordinality ( ,, Row)\n└── Domain  (Valie of Vplumn)\n```\n## ✅ RDBMS Relationship \u003ca name=\"RDBMS-Relationship\"\u003e\u003c/a\u003e\n```yaml\nRDBMS Relationship\n│\n│── One to One: 1:1\n│── One to many: 1:M\n└── Many to Many\n```\n- **One to One: 1:1** : If each record (01 or 02...) of a table is related only rach racord of another table.\u003cbr\u003e\n- **One to many: 1:M** : If one Record of a table is enter related to multiple records of another table.\n\n```yaml\n+-----------------+     +-----------------+               +------------------------+      +-------------------------------+\n│ No.  | Name     |     │ No.  | Place    |               │ Customer ID | Name     |      │ No.  | Customer ID | Orders   |\n│ 101  | Akashdip |     │ 101  | Haldia   |               │ 01          | Akashdip |      │ 106  | 01          | i Phon7  |\n│ 102  | Suman    |     │ 102  | Asansole |               │ 02          | Suman    |      │ 107  | 01          | Laptop   |\n+-----------------+     +-----------------+               +------------------------+      │ 108  | 02          | Phon16   |\n                                                                                          +-------------------------------+\nin 1:1 --\u003e 01, Akashdip, Haldia                          But in 1:M case a persan can order many items.\n```\n\n## ✅ Schema \u003ca name=\"schema\"\u003e\u003c/a\u003e\n\n- Schema is a blue-print that defines the structure of database.\n- It's includes the table, columns, data-types, relationship \u0026 constrains.\n- Schema tells how data stored and related.\n\n### see the Schema (Structure of the Table)\n```sql\nSQL\u003e create table student(name varchar(12),address varchar2(20),phone_no number)\nSQL\u003e desc student\n```\n## ✅ Key \u003ca name=\"key\"\u003e\u003c/a\u003e\n\n- Key is the `data item` in RDBMS which exclusively `identify the records` of table.\n- **☀️ Primary Key :** it's a key field `uniqly identify eatch racord` of table. ⚠️ Eatch column has a unique value\n- **☀️ Candidate Key :** If many column has unique value ⚠️ but onlu one Column is `Primary Key`,✅ So one of anothers is `Condidate Kay`.\n- **☀️ Alternate Key :**  If many column has unique value ⚠️ but onlu one Column is `Primary Key`,✅ So all other `eligible` (unique value) columns are `Alternate key`. \n- **☀️ Composite Key :** If two column has no unique value❌ but the combination of this type of two columns are create a unique (marge) column.\n- **☀️ Foreign Key :** uniqly identify the records of another table.\n- **☀️ Unique Key :** `same` --\u003e use to identify unique records from a table. But it's allow `NULL` but Primary Key not.\n\n## ✅ ER Model \u003ca name=\"er-model\"\u003e\u003c/a\u003e\n\n- ER --\u003e Entity relationship model. [Video Link](https://youtu.be/GBjLgU1WZvo)\n- also known as Conceptual frameWork, use to describe and design the structure of a database.\n  │\n  │── The graphical representation of relationship of table is called ER-diagram.\n  └── and The model through which use describe the relationship called ER-model.\n\n```yaml\n  Relationship\n     │\n     │── 1:1\n     │── 1: M\n     └── M:M\n```  \n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n# 3. SQL Basics \u003ca name=\"sql-basics\"\u003e\u003c/a\u003e\n\n**SQL (Structured Query Language)** is the standard language for interacting with RDBMS. **ANSI SQL** is the standardized version of SQL.\n\n### Basic Syntax\n```sql\n-- Select all columns from a table\nSELECT * FROM table_name;\n\n-- Insert a new row into a table\nINSERT INTO table_name (column1, column2) VALUES (value1, value2);\n\n-- Update a row in a table\nUPDATE table_name SET column1 = value1 WHERE condition;\n\n-- Delete rows from a table\nDELETE FROM table_name WHERE condition;\n```\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n## 4. Data Definition Language (DDL) \u003ca name=\"ddl\"\u003e\u003c/a\u003e\n\nDDL commands are used to define and modify the structure of database objects.\n\n- **CREATE**: Creates tables, views, or other objects.\n- **ALTER**: Modifies existing structures.\n- **DROP**: Deletes tables, views, or other objects.\n\n### ✈️ Syntax\n\n### **CREATE Table**\n```sql\nsql\u003e CREATE TABLE employees (\n       employee_id INT PRIMARY KEY,\n       name VARCHAR(50),\n       department VARCHAR(50),\n       salary DECIMAL(10, 2)\n     );\n\n# Output:\nTable 'employees' created successfully.\n```\n### Show the Table\n```sql\ndesc employees\n```\n\n### **ALTER Table**\n\n`The ALTER Command allow us to altering the structure of object like- add a new Column, drop or Rename a Column, add Constraint etc.`\n\n```sql\n# 1. Add a New Column\nALTER TABLE employees ADD age INT;\n\n# 2. Rename an Existing Column\nALTER TABLE employees RENAME COLUMN age TO years_of_experience;\n\n# 3. Modify an Existing Column\nALTER TABLE employees MODIFY years_of_experience DECIMAL(3, 1);\n\n# 4. Rename the Table\nALTER TABLE employees RENAME TO staff;\n\n# 5. Add a Constraint\nALTER TABLE employees ADD CONSTRAINT chk_salary CHECK (salary \u003e 0);\n\n# 6. Drop a Column\nALTER TABLE employees DROP COLUMN years_of_experience;\n\n# 7. Drop a Constraint\nALTER TABLE employees DROP CONSTRAINT chk_salary;\n```\n\n### **DROP Table**\n```sql\nsql\u003e DROP TABLE employees;\n\n# Output:\nTable 'employees' dropped successfully.\n```\n\n---\n\n## 5. Data Manipulation Language (DML) \u003ca name=\"dml\"\u003e\u003c/a\u003e\n\nDML commands are used to manipulate data in tables.\n\n- **SELECT**: Retrieves data from a table.\n- **INSERT**: Adds new data to a table.\n- **UPDATE**: Modifies existing data in a table.\n- **DELETE**: Removes data from a table.\n\n### Syntax\n\n```sql\n-- Select data from a table\nSELECT name, department FROM employees;\n\n-- Insert data into a table\nINSERT INTO employees (employee_id, name, department, salary) VALUES (101, 'Alice', 'HR', 55000);\n\n-- Update data in a table\nUPDATE employees SET salary = 60000 WHERE name = 'Alice';\n\n-- Delete data from a table\nDELETE FROM employees WHERE name = 'Alice';\n```\n\n### Explane \n### **SELECT Statement**\n```sql\n# Command Line Interface:\nsql\u003e SELECT name, department FROM employees;\n\n# Output:\n| name    | department |\n|---------|------------|\n| Alice   | HR         |\n| Bob     | Finance    |\n| Charlie | IT         |\n```\n\n### **INSERT Statement**\n```sql\n# Command Line Interface:\nsql\u003e INSERT INTO employees (employee_id, name, department, salary) \n       VALUES (101, 'Alice', 'HR', 55000);\n\n# Output:\n1 row inserted.\n```\n\n### **UPDATE Statement**\n```sql\n# Command Line Interface:\nsql\u003e UPDATE employees SET salary = 60000 WHERE name = 'Alice';\n\n# Output:\n1 row updated.\n```\n\n### **DELETE Statement**\n```sql\n# Command Line Interface:\nsql\u003e DELETE FROM employees WHERE name = 'Alice';\n\n# Output:\n1 row deleted.\n```\n\n---\n\n## 6. Data Control Language (DCL) \u003ca name=\"dcl\"\u003e\u003c/a\u003e\n\nDCL commands manage permissions and access controls.\n\n- **GRANT**: Grants user permissions on database objects.\n- **REVOKE**: Removes user permissions.\n\n### Example Syntax and Output\n\n```sql\n-- Grant SELECT permission to a user\nGRANT SELECT ON employees TO user_name;\n\n-- Revoke SELECT permission from a user\nREVOKE SELECT ON employees FROM user_name;\n```\n\n---\n\n## 7. Transaction Control Language (TCL) \u003ca name=\"tcl\"\u003e\u003c/a\u003e\n\nTCL commands control database transactions.\n\n- **COMMIT**: Saves changes made in the current transaction.\n- **ROLLBACK**: Reverts changes made in the current transaction.\n- **SAVEPOINT**: Sets a point in a transaction to which you can rollback.\n\n### Example Syntax and Output\n\n```sql\n-- Start a transaction\nBEGIN TRANSACTION;\n\n-- Update statement\nUPDATE employees SET salary = salary + 500 WHERE department = 'HR';\n\n-- Commit the transaction\nCOMMIT;\n\n-- Rollback if needed\nROLLBACK;\n```\n\n---\n\n## 8. Constraints and Their Types \u003ca name=\"constraints\"\u003e\u003c/a\u003e\n\nConstraints enforce data integrity by defining rules for columns.\n\n- **PRIMARY KEY**: Uniquely identifies each row in a table.\n- **FOREIGN KEY**: References a primary key in another table.\n- **UNIQUE**: Ensures unique values in a column.\n- **NOT NULL**: Prevents null values.\n- **CHECK**: Enforces a condition on values.\n\n### Example Syntax and Output\n\n```sql\n-- Create a table with constraints\nCREATE TABLE orders (\n    order_id INT PRIMARY KEY,\n    product_id INT NOT NULL,\n    quantity INT CHECK (quantity \u003e 0),\n    FOREIGN KEY (product_id) REFERENCES products(product_id)\n);\n```\n\n---\n\n## 9. SQL Operators \u003ca name=\"sql-operators\"\u003e\u003c/a\u003e\n\nOperators in SQL are used for calculations and comparisons.\n\n- **Arithmetic Operators**: `+`, `-`, `*`, `/`, `%`\n- **Comparison Operators**: `=`, `\u003c`, `\u003e`, `\u003c=`, `\u003e=`, `\u003c\u003e`\n- **Logical Operators**: `AND`, `OR`, `NOT`\n\n### ✅ Syntax \n\n```sql\n-- Arithmetic operators\nSELECT salary * 1.1 AS increased_salary FROM employees;\n\n-- Comparison operators\nSELECT * FROM employees WHERE salary \u003e 50000;\n\n-- Logical operators\nSELECT * FROM employees WHERE department = 'HR' AND salary \u003e 50000;\n```\n\n### ✈️ Explane \n### **Arithmetic Operators**\n```sql\n# Command Line Interface:\nsql\u003e SELECT salary * 1.1 AS increased_salary FROM employees;\n\n# Output:\n| increased_salary |\n|------------------|\n| 60500.00         |\n| 66000.00         |\n| 71500.00         |\n```\n\n### **Comparison Operators**\n```sql\n# Command Line Interface:\nsql\u003e SELECT * FROM employees WHERE salary \u003e 50000;\n\n# Output:\n| employee_id | name  | department | salary |\n|-------------|-------|------------|--------|\n| 102         | Bob   | Finance    | 55000  |\n| 103         | Carol | IT         | 60000  |\n```\n\n---\n\n## 10. SQL Functions \u003ca name=\"sql-functions\"\u003e\u003c/a\u003e\n\nSQL functions perform operations on data.\n\n- **Aggregate Functions**: Operate on multiple rows (e.g., `COUNT`, `SUM`, `AVG`, `MIN`, `MAX`).\n- **String Functions**: Manipulate string values (e.g., `UPPER`, `LOWER`, `CONCAT`).\n- **Date Functions**: Work with date values (e.g., `NOW`, `DATEADD`).\n\n### ✅ Syntax\n\n```sql\n-- Aggregate function\nSELECT COUNT(*) AS total_employees FROM employees;\n\n-- String function\nSELECT UPPER(name) AS uppercase_name FROM employees;\n\n-- Date function\nSELECT NOW() AS current_date_time;\n```\n\n### ✈️ Explane\n### **Aggregate Functions**\n```sql\n# Command Line Interface:\nsql\u003e SELECT COUNT(*) AS total_employees FROM employees;\n\n# Output:\n| total_employees |\n|-----------------|\n| 5               |\n```\n\n### **String Functions**\n```sql\n# Command Line Interface:\nsql\u003e SELECT UPPER(name) AS uppercase_name FROM employees;\n\n# Output:\n| uppercase_name |\n|----------------|\n| ALICE          |\n| BOB            |\n| CHARLIE        |\n```\n\n---\n\n## 11. SQL Clauses \u003ca name=\"sql-clauses\"\u003e\u003c/a\u003e\n\nSQL clauses refine query results.\n\n- **WHERE**: Filters results based on a condition.\n- **GROUP BY**: Groups results by one or more columns.\n- **ORDER BY**: Sorts the result set.\n- **HAVING**: Filters groups.\n- **LIMIT**: Limits the number of results returned.\n\n### ✅ Syntax\n\n```sql\n-- WHERE clause\nSELECT * FROM employees WHERE department = 'Finance';\n\n-- GROUP BY clause\nSELECT department, COUNT(*) FROM employees GROUP BY department;\n\n-- ORDER BY clause\nSELECT * FROM employees ORDER BY salary DESC;\n\n-- HAVING clause\nSELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) \u003e 50000;\n\n-- LIMIT clause\nSELECT * FROM employees LIMIT 5;\n```\n\n### ✈️ Explane\n### **WHERE Clause**\n```sql\n# Command Line Interface:\nsql\u003e SELECT * FROM employees WHERE department = 'Finance';\n\n# Output:\n| employee_id | name | department | salary |\n|-------------|------|------------|--------|\n| 102         | Bob  | Finance    | 55000  |\n```\n\n### **GROUP BY Clause**\n```sql\n# Command Line Interface:\nsql\u003e SELECT department, COUNT(*) FROM employees GROUP BY department;\n\n# Output:\n| department | count |\n|------------|-------|\n| HR         | 2     |\n| IT         | 1     |\n| Finance    | 1     |\n```\n\n### **ORDER BY Clause**\n```sql\n# Command Line Interface:\nsql\u003e SELECT * FROM employees ORDER BY salary DESC;\n\n# Output:\n| employee_id | name    | department | salary |\n|-------------|---------|------------|--------|\n| 103         | Charlie | IT         | 60000  |\n| 102         | Bob     | Finance    | 55000  |\n| 101         | Alice   | HR         | 50000  |\n```\n\n---\n\n## 12. Joins and Their Types \u003ca name=\"joins\"\u003e\u003c/a\u003e\n\nJoins combine rows from two or more tables.\n\n- **INNER JOIN**: Returns rows with matching values in both tables.\n- **LEFT JOIN**: Returns all rows from the left table and matched rows from the right.\n- **RIGHT JOIN**: Returns all rows from the right table and matched rows from the left.\n- **FULL JOIN**: Returns rows with a match in either table.\n\n### ✅ Syntax \n\n```sql\n-- Inner join example\nSELECT employees.name, departments.department_name\nFROM employees\nINNER JOIN departments ON employees.department_id = departments.department_id;\n\n-- Left join example\nSELECT employees.name, departments.department_name\nFROM employees\nLEFT JOIN departments ON employees.department_id = departments.department_id;\n```\n\n### ✈️ Explane\n### **INNER JOIN**\n```sql\n# Command Line Interface:\nsql\u003e SELECT employees.name, departments.department_name\n       FROM employees\n       INNER JOIN departments ON employees.department_id = departments.department_id;\n\n# Output:\n| name   | department_name |\n|--------|-----------------|\n| Alice  | HR             |\n| Bob    | Finance        |\n```\n\n### **LEFT JOIN**\n```sql\n# Command Line Interface:\nsql\u003e SELECT employees.name, departments.department_name\n       FROM employees\n       LEFT JOIN departments ON employees.department_id = departments.department_id;\n\n# Output:\n| name   | department_name |\n|--------|-----------------|\n| Alice  | HR             |\n| Bob    | Finance        |\n| Carol  | NULL           |\n```\n\n---\n\n## 13. Subqueries \u003ca name=\"subqueries\"\u003e\u003c/a\u003e\n\nSubqueries are queries embedded within other queries to return a result used in the outer query.\n\n### Example Syntax and Output\n\n```sql\n-- Subquery example to find employees with above-average salary\nsql\u003e SELECT name FROM employees WHERE salary \u003e (SELECT AVG(salary) FROM employees);\n\n# Output:\n| name    |\n|---------|\n| Bob     |\n| Charlie |\n```\n\n---\n\n## 14. Views \u003ca name=\"views\"\u003e\u003c/a\u003e\n\nA view is a virtual table based on a query result. Views provide security by limiting user access to specific data.\n\n### ✅ Syntax\n\n```sql\n-- Create a view\nCREATE VIEW high_salary_employees AS\nSELECT * FROM employees WHERE salary \u003e 60000;\n\n-- Select from view\nSELECT * FROM high_salary_employees;\n```\n\n### ✈️ Explane\n```sql\n# Command Line Interface:\nsql\u003e CREATE VIEW high_salary_employees AS\n       SELECT * FROM employees WHERE salary \u003e 60000;\n\n# Output:\nView 'high_salary_employees' created successfully.\n\nsql\u003e SELECT * FROM high_salary_employees;\n\n# Output:\n| employee_id | name    | department | salary |\n|-------------|---------|------------|--------|\n| 104         | David   | IT         | 75000  |\n```\n\n---\n\n## 12. Indexes\n\n### **Create an Index**\n```sql\n# Command Line Interface:\nsql\u003e CREATE INDEX idx_salary ON employees (salary);\n\n# Output:\nIndex 'idx_salary' created on 'employees' table.\n\nsql\u003e SELECT name FROM employees WHERE salary \u003e 50000;\n\n# Output (using index for faster retrieval):\n| name    |\n|---------|\n| Bob     |\n| Charlie |\n```\n\n---\n\n## 15. Indexes \u003ca name=\"indexes\"\u003e\u003c/a\u003e\n\nIndexes improve the speed of data retrieval operations on a database table. However, they can slow down data modification.\n\n### Example Syntax and Output\n\n```sql\n-- Create an index on the salary column\nCREATE INDEX idx_salary ON employees (salary);\n\n-- Use index in a query\nSELECT name FROM employees WHERE salary \u003e 50000;\n```\n\n---\n\n### Practice Questions\n1. Write a query to find the highest-paid employee in each department.\n2. Create a query to list all employees hired after 2015.\n3. Write a query to list products with no sales.\n\nThis structure covers all foundational SQL topics, organized with examples to give you a solid ANSI SQL foundation for job exam.\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n# practical\n### [pdf Notes](https://drive.google.com/file/d/1coREmAmIW34bkyvbZPbR71dONkX0Z8Qv/view?usp=drivesdk)\n# 1) Creat Databases \n\n```go\n✅ 1) GUI option ----\u003e CREATE SCHEMA `schema_01` ;\n✅ 2) GUI Command ---\u003e CREATE DATABASE first_db\n✅ 3) CLI Command ---\u003e CREATE DATABASE first01_db;\n```\n| GUI option | GUI Command |\n| --- | --- |\n| `CREATE SCHEMA `schema_01` ;` | `CREATE DATABASE first_db` |\n\n\u003cdiv style=\"display: flex; justify-content: space-around;\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/427ca07d-9348-4354-a02b-3736ea929383\" alt=\"python projects\" style=\"width: 45%; height: auto;\"/\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/6d059a42-cb50-4e3c-9d18-ee34e96e974d\" alt=\"pythonprojects\" style=\"width: 45%; height: auto;\"/\u003e\n\u003c/div\u003e\n\n---\n# 2) Chouse a Database (or Enter or Use a DB) using CLI \u0026 check\n\n```sql\nUSE first_db;\nselect database();\n```\n\n\u003cdiv style=\"display: flex; justify-content: space-around;\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/665e8edc-4e57-4289-aa72-d93cb9dbba1c\" alt=\"python projects\" style=\"width: 45%; height: auto;\"/\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/c9cc5f7e-ba0e-47b6-bb82-b85ac116a999\" alt=\"pythonprojects\" style=\"width: 45%; height: auto;\"/\u003e\n\u003c/div\u003e\n\n# 3) Delete Database\n```sql\n DROP DATABASE first2_db;\n```\n![Screenshot (45)](https://github.com/user-attachments/assets/0a9c7281-dfc6-47d8-b9b0-009dbb134da7)\n\n\u003cimg src=\"https://github.com/akashdip2001/college-final-year-project/blob/main/img/colour_line.png\"\u003e\n\n# EXAM\n\n# 1) Problam 01\n![SQL_01](https://github.com/user-attachments/assets/75228002-093a-4ab9-86fb-2255c29ae215)\n### QUERY ✅\n```sql\nSELECT\n  Account_Type_ID,\n  COUNT(*) AS Account_Count\nFROM\n  Account\nGROUP BY\n  Account_Type_ID;\n```\n\n---\n# 2) Problam 02\n\n\u003cdiv style=\"display: flex; justify-content: space-around;\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/1c94cff0-40e4-4242-a0ea-6bb459598d3c\" alt=\"python projects\" style=\"width: 50%; height: auto;\"/\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/ad066fbd-3ee8-4014-b59b-829378466e12\" alt=\"pythonprojects\" style=\"width: 40%; height: auto;\"/\u003e\n\u003c/div\u003e\n\n### QUERY ⚠️\n\n```sql\nSELECT \n    Account_Type_ID, \n    COUNT(*) AS Account_Count\nFROM \n    account\nGROUP BY \n    Account_Type_ID;\n\n```\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashdip2001%2Fsql-study-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakashdip2001%2Fsql-study-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakashdip2001%2Fsql-study-notes/lists"}