{"id":27149036,"url":"https://github.com/chhaya03/sql","last_synced_at":"2026-02-14T08:03:27.451Z","repository":{"id":275293155,"uuid":"925665405","full_name":"chhaya03/SQL","owner":"chhaya03","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-24T19:35:36.000Z","size":75,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-07T17:51:39.405Z","etag":null,"topics":["sql"],"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/chhaya03.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":"2025-02-01T12:43:00.000Z","updated_at":"2025-05-27T18:48:36.000Z","dependencies_parsed_at":"2025-02-24T20:26:30.589Z","dependency_job_id":"4dcffdcf-d201-4f80-b67c-d0004b64a1b8","html_url":"https://github.com/chhaya03/SQL","commit_stats":null,"previous_names":["chhaya03/sql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chhaya03/SQL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chhaya03%2FSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chhaya03%2FSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chhaya03%2FSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chhaya03%2FSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chhaya03","download_url":"https://codeload.github.com/chhaya03/SQL/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chhaya03%2FSQL/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29439821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T07:24:13.446Z","status":"ssl_error","status_checked_at":"2026-02-14T07:23:58.969Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["sql"],"created_at":"2025-04-08T12:35:21.343Z","updated_at":"2026-02-14T08:03:27.435Z","avatar_url":"https://github.com/chhaya03.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL\n\n\u003ch1\u003eWhat is Database?\u003c/h1\u003e\nDatabase is a collection of interrelated data.\n\n\u003ch1\u003eWhat is DBMS?\u003c/h1\u003e\nDBMS (Database Management System) is software used to create, manage, and organize\ndatabases.\n\n\u003ch1\u003eWhat is RDBMS?\n\u003c/h1\u003e\n● RDBMS (Relational Database Management System) - is a DBMS based on the\nconcept of tables (also called relations).\u003cbr\u003e\n● Data is organized into tables (also known as relations) with rows (records) and\ncolumns (attributes).\u003cbr\u003e\n● Eg - MySQL, PostgreSQL, Oracle etc.\n\n\n\u003ch1\u003eWhat is SQL?\u003c/h1\u003e\nSQL is Structured Query Language - used to store, manipulate and retrieve data from\nRDBMS.\n(It is not a database, it is a language used to interact with database)\n\n\u003ch3\u003eWe use SQL for CRUD Operations :\u003c/h3\u003e\u003cbr\u003e\n● CREATE - To create databases, tables, insert tuples in tables etc\u003cbr\u003e\n● READ - To read data present in the database.\u003cbr\u003e\n● UPDATE - Modify already inserted data.\u003cbr\u003e\n● DELETE - Delete database, table or specific data point/tuple/row or multiple rows.\u003cbr\u003e\n\n*Note - SQL keywords are NOT case sensitive. Eg: select is the same as SELECT in SQL.\n\n\n\u003ch1\u003eSQL v/s MySQL\u003c/h1\u003e\nSQL is a language used to perform CRUD operations in Relational DB, while MySQL is a\nRDBMS that uses SQL.\u003cbr\u003e\n\n\n\u003ch1\u003eSQL Data Types\u003c/h1\u003e\nIn SQL, data types define the kind of data that can be stored in a column or variable.\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eDATATYPE \u003c/td\u003e\n    \u003ctd\u003eDESCRIPTION\u003c/td\u003e\n    \u003ctd\u003eUSAGE\n\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003e\n      CHAR\n    \u003c/td\u003e\n    \u003ctd\u003estring(0-255), can store characters of fixed length\u003c/td\u003e\n    \u003ctd\u003e CHAR(50)\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eVARCHAR\u003c/td\u003e\n    \u003ctd\u003estring(0-255), can store characters up to given length\u003c/td\u003e\n    \u003ctd\u003eVARCHAR(50\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eBLOB \u003c/td\u003e\n    \u003ctd\u003estring(0-65535), can store binary large object\u003c/td\u003e\n    \u003ctd\u003eBLOB(1000)\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eINT \u003c/td\u003e\n    \u003ctd\u003einteger( -2,147,483,648 to 2,147,483,647 )\u003c/td\u003e\n    \u003ctd\u003eINT\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eTINYINT\u003c/td\u003e\n    \u003ctd\u003enteger(-128 to 127) \u003c/td\u003e\n    \u003ctd\u003eTINYINT\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eBIGINT \u003c/td\u003e\n    \u003ctd\u003einteger( -9,223,372,036,854,775,808 to\n9,223,372,036,854,775,807 )\n\u003c/td\u003e\n    \u003ctd\u003eBIGINT\n\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eBIT\u003c/td\u003e\n    \u003ctd\u003ecan store x-bit values. x can range from 1 to 64 \u003c/td\u003e\n    \u003ctd\u003eBIT(2)\n\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eFLOAT\u003c/td\u003e\n    \u003ctd\u003eDecimal number - with precision to 23 digits\u003c/td\u003e\n    \u003ctd\u003eFLOAT\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eDOUBLE\u003c/td\u003e\n    \u003ctd\u003eDecimal number - with 24 to 53 digits\u003c/td\u003e\n    \u003ctd\u003eDOUBLE\u003c/td\u003e\n  \u003c/tr\u003e\n\n  \u003ctr\u003e\n    \u003ctd\u003eBOOLEAN\u003c/td\u003e\n    \u003ctd\u003eBoolean values 0 or 1\u003c/td\u003e\n    \u003ctd\u003eBOOLEAN\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eDATE\u003c/td\u003e\n    \u003ctd\u003edate in format of YYYY-MM-DD ranging from\n1000-01-01 to 9999-12-31\n\u003c/td\u003e\n    \u003ctd\u003eDATE\n\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eTIME\u003c/td\u003e\n    \u003ctd\u003eHH:MM:SS \u003c/td\u003e\n    \u003ctd\u003eTIME\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003eYEAR\u003c/td\u003e\n    \u003ctd\u003eyear in 4 digits format ranging from 1901 to 2155\u003c/td\u003e\n    \u003ctd\u003eYEAR\u003c/td\u003e\n \n\u003c/table\u003e\n\n\u003ch3\u003e*Note -\u003c/h3\u003e CHAR is for fixed length \u0026 VARCHAR is for variable length strings. Generally,\nVARCHAR is better as it only occupies necessary memory \u0026 works more efficiently.\u003cbr\u003e\nWe can also use UNSIGNED with datatypes when we only have positive values to add.\nEg - UNSIGNED INT\n\n\n\u003ch1\u003eTypes of SQL Commands:\n\u003c/h1\u003e\n1. DQL(Data Query Language) : Used to retrieve data from databases. (SELECT)\u003cbr\u003e\n 2. DDL(Data Definition Language) : Used to create, alter, and delete database objects\n like tables, indexes, etc. (CREATE, DROP, ALTER, RENAME, TRUNCATE)\u003cbr\u003e\n 3. DML(Data Manipulation Language): Used to modify the database. (INSERT,\n UPDATE, DELETE)\u003cbr\u003e\n 4. DCL(Data Control Language): Used to grant \u0026 revoke permissions. (GRANT,\n REVOKE)\u003cbr\u003e\n 5. TCL(Transaction Control Language): Used to manage transactions. (COMMIT,\n ROLLBACK, START TRANSACTIONS, SAVEPOINT)\u003cbr\u003e\n\n\n \u003ch2\u003e1. Data Definition Language (DDL)\u003c/h2\u003e\n  Data Definition Language (DDL) is a subset of SQL (Structured Query Language)\n responsible for defining and managing the structure of databases and their objects.\n DDL commands enable you to create, modify, and delete database objects like tables,\n indexes, constraints, and more.\u003cbr\u003e\n  Key DDL Commands are:\n\n \u003ch3\u003e ● CREATE TABLE:\u003c/h3\u003e\n ○ Used to create a new table in the database.\u003cbr\u003e\n ○ Specifies the table name, column names, data types, constraints, and more.\u003cbr\u003e\n ○ Example:CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(50),\n salary DECIMAL(10, 2));\n\n \u003ch3\u003e ● ALTER TABLE:\u003c/h3\u003e\n  ○ Used to modify the structure of an existing table.\u003cbr\u003e\n ○ You can add, modify, or drop columns, constraints, and more.\u003cbr\u003e\n ○ Example: ALTER TABLE employees ADD COLUMN email VARCHAR(100);\u003cbr\u003e\n\n \u003ch3\u003e● DROP TABLE:\u003c/h3\u003e\n ○ Used to delete an existing table along with its data and structure.\u003cbr\u003e\n ○ Example: DROP TABLE employees;\n\n\u003ch3\u003e● CREATE INDEX:\u003c/h3\u003e\n ○ Used to create an index on one or more columns in a table.\u003cbr\u003e\n ○ Improves query performance by enabling faster data retrieval.\u003cbr\u003e\n ○ Example: CREATE INDEX idx_employee_name ON employees (name);\n\n\n \u003ch3\u003e● DROP INDEX:\u003c/h3\u003e\n ○ Used to remove an existing index from a table.\u003cbr\u003e\n ○ Example: DROP INDEX idx_employee_name;\u003cbr\u003e\n\n\n \u003ch3\u003e● CREATE CONSTRAINT:\u003c/h3\u003e\n ○ Used to define constraints that ensure data integrity.\u003cbr\u003e\n ○ Constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL,\n and CHECK.\u003cbr\u003e\n ○ Example: ALTER TABLE orders ADD CONSTRAINT fk_customer FOREIGN\n KEY (customer_id) REFERENCES customers(id);\n\n\n \u003ch3\u003e● DROP CONSTRAINT:\u003c/h3\u003e\n ○ Used to remove an existing constraint from a table.\u003cbr\u003e\n ○ Example: ALTER TABLE orders DROP CONSTRAINT fk_customer;\u003cbr\u003e\n\n\u003ch3\u003e ● TRUNCATE TABLE:\u003c/h3\u003e\n ○ Used to delete the data inside a table, but not the table itself.\u003cbr\u003e\n ○ Syntax– TRUNCATETABLEtable_name\n\n\n \u003ch2\u003e2. DATA QUERY/RETRIEVAL LANGUAGE (DQL or DRL)\u003c/h2\u003e\n  DQL (Data Query Language) is a subset of SQL focused on retrieving data from databases.\n The SELECT statement is the foundation of DQL and allows us to extract specific columns\n from a table.\n\n \u003ch3\u003e ● SELECT:\u003c/h3\u003e\n The SELECT statement is used to select data from a database.\u003cbr\u003e\nSyntax: SELECT column1, column2, ... FROM table_name;\u003cbr\u003e\n Here, column1, column2, ... are the field names of the table.\n If you want to select all the fields available in the table, use the following syntax:\n SELECT * FROMtable_name;\u003cbr\u003e\n Ex: SELECT CustomerName, City FROM Customers;\n \n\u003ch3\u003e ● WHERE:\u003c/h3\u003e\n The WHEREclause is used to filter records.\u003cbr\u003e\n Syntax: SELECT column1, column2, ... FROM table_name WHERE condition;\u003cbr\u003e\n Ex: SELECT * FROM Customers WHERE Country='Mexico';\u003cbr\u003e\n\u003ch4\u003e Operators used in WHERE are:\u003c/h4\u003e\n = :Equal\u003cbr\u003e\n \u003e :Greater than\u003cbr\u003e\n \u003c :Less than \u003cbr\u003e\n \u003e= : Greater than or equal\u003cbr\u003e\n \u003c= : Less than or equal\u003cbr\u003e\n \u003c\u003e : Not equal.\u003cbr\u003e\n Note: In some versions of SQL this operator may be written as !=\n   \n\u003ch3\u003e ● AND,OR and NOT:\u003c/h3\u003e\nThe WHEREclause can be combined with AND, OR, and NOT operators.\u003cbr\u003e\n The AND and ORoperators are used to filter records based on more than one\n condition:\u003cbr\u003e\n The AND operator displays a record if all the conditions separated by AND are\n TRUE.\u003cbr\u003e\n The ORoperator displays a record if any of the conditions separated by OR is TRUE.\u003cbr\u003e\n The NOT operator displays a record if the condition(s) is NOT TRUE.\u003cbr\u003e\n\u003ch4\u003e Syntax:\u003c/h4\u003e\nSELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND\n condition3 ...;\u003cbr\u003e\n SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR\n condition3 ...;\u003cbr\u003e\n SELECT column1, column2, ... FROM table_name WHERE NOT condition;\n Example:\u003cbr\u003e\n SELECT * FROMCustomers WHERE Country=’India’ AND City=’Japan’;\u003cbr\u003e\n SELECT * FROMCustomers WHERE Country=’America’ AND (City=’India’ OR\n City=’Korea’);\n   \n\u003ch3\u003e ● DISTINCT:\u003c/h3\u003e\n Removes duplicate rows from query results.\u003cbr\u003e\n Syntax: SELECT DISTINCT column1, column2 FROM table_name;\n \n\u003ch3\u003e ● LIKE:\u003c/h3\u003e\n The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.\u003cbr\u003e\n There are two wildcards often used in conjunction with the LIKE operator:--\u003cbr\u003e\n The percent sign (%) represents zero, one, or multiple characters\n The underscore sign (_) represents one, single character\u003cbr\u003e\n Example: SELECT * FROM employees WHERE first_name LIKE 'J%';\u003cbr\u003e\n WHERECustomerName LIKE 'a%'\u003cbr\u003e\nFinds any values that start with \"a\"\u003cbr\u003e\n WHERECustomerName LIKE '%a'\u003cbr\u003e\nFinds any values that end with \"a\"\u003cbr\u003e\n WHERECustomerName LIKE '%or%'\u003cbr\u003e\nFinds any values that have \"or\" in any position\u003cbr\u003e\n WHERECustomerName LIKE '_r%'\u003cbr\u003e\nFinds any values that have \"r\" in the second position\u003cbr\u003e\nWHERECustomerName LIKE 'a_%'\u003cbr\u003e\nFinds any values that start with \"a\" and are at least 2 characters in length\u003cbr\u003e\n WHERECustomerName LIKE 'a__%'\u003cbr\u003e\nFinds any values that start with \"a\" and are at least 3 characters in length\u003cbr\u003e\n WHEREContactName LIKE 'a%o'\u003cbr\u003e\nFinds any values that start with \"a\" and ends with \"o\"\u003cbr\u003e\n\n\u003ch3\u003e ● IN:\u003c/h3\u003e\n Filters results based on a list of values in the WHERE clause.\u003cbr\u003e\n Example: SELECT * FROM products WHERE category_id IN (1, 2, 3);\n \n\u003ch3\u003e ● BETWEEN:\u003c/h3\u003e\n Filters results within a specified range in the WHERE clause.\u003cbr\u003e\n Example: SELECT * FROM orders WHERE order_date BETWEEN '2023-01-01' AND\n '2023-06-30';\n \n\u003ch3\u003e ● IS NULL:\u003c/h3\u003e\n Checks for NULL values in the WHERE clause.\u003cbr\u003e\n Example: SELECT * FROM customers WHERE email IS NULL;\n \n\u003ch3\u003e ● AS:\u003c/h3\u003e\n Renames columns or expressions in query results.\u003cbr\u003e\n Example: SELECT first_name AS \"First Name\", last_name AS \"Last Name\" FROM\n employees;\n \n\u003ch3\u003e ● ORDER BY\u003c/h3\u003e\n The ORDERBYclause allows you to sort the result set of a query based on one or more\n columns.\n \n\u003ch4\u003e Basic Syntax:\u003c/h4\u003e\nThe ORDER BY clause is used after the SELECT statement to sort query results.\nSyntax:SELECT column1, column2 FROM table_name ORDER BY column1\n [ASC|DESC];\n \u003ch4\u003e\n Ascending and Descending Order:---\u003c/h4\u003e\nBy default, the ORDER BY clause sorts in ascending order (smallest to largest).\u003cbr\u003e\n You can explicitly specify descending order using the DESC keyword.\u003cbr\u003e\n Example: SELECT product_name, price FROM products ORDER BY price DESC;\n \n\u003ch4\u003e Sorting by Multiple Columns:--\u003c/h4\u003e\nYou can sort by multiple columns by listing them sequentially in the ORDER BY\n clause.\u003cbr\u003e\n Rows are first sorted based on the first column, and for rows with equal values,\n subsequent columns are used for further sorting.\u003cbr\u003e\n Example: SELECT first_name, last_name FROM employees ORDER BY last_name,\n first_name;\n \n \u003ch4\u003eSorting by Expressions:--\u003c/h4\u003e\n It's possible to sort by calculated expressions, not just column values.\u003cbr\u003e\n Example: SELECT product_name, price, price * 1.1 AS discounted_price FROM\n products ORDER BY discounted_price;\n\u003ch4\u003e Sorting NULL Values:--\u003c/h4\u003e\u003cbr\u003e\nBy default, NULL values are considered the smallest in ascending order and the\n largest in descending order.\u003cbr\u003e\n You can control the sorting behaviour of NULL values using the NULLS FIRST or\n NULLS LAST options.\u003cbr\u003e\n Example: SELECT column_name FROM table_name ORDER BY column_name\n NULLS LAST;\n \n \u003ch4\u003eSorting by Position:--\u003c/h4\u003e\n Instead of specifying column names, you can sort by column positions in the ORDER\n BY clause.\u003cbr\u003e\n Example: SELECT product_name, price FROM products ORDER BY 2 DESC, 1\n ASC;\n \n\u003ch3\u003e ● GROUP BY\u003c/h3\u003e\n The GROUPBYclause in SQL is used to group rows from a table based on one or more\n columns.\u003cbr\u003e\n Syntax: The GROUPBYclause follows the SELECT statement and is used to group rows\n based on specified columns.\u003cbr\u003e\nSyntax: SELECT column1, aggregate_function(column2) FROM table_name\n GROUPBYcolumn1; \n \n\u003ch4\u003e Aggregation Functions:---\u003c/h4\u003e\n ○ Aggregation functions (e.g., COUNT, SUM, AVG, MAX, MIN) are often used\n with GROUP BY to calculate values for each group.\u003cbr\u003e\n ○ Example: SELECT department, AVG(salary) FROM employees GROUP BY\n department;\u003cbr\u003e\n \n \u003ch4\u003eGrouping by Multiple Columns:---\u003c/h4\u003e\n ○ Youcangroup by multiple columns by listing them in the GROUP BY clause.\u003cbr\u003e\n ○ Thiscreates a hierarchical grouping based on the specified columns.\u003cbr\u003e\n ○ Example: SELECT department, gender, AVG(salary) FROM employees\n GROUPBYdepartment, gender;\n \n\u003ch4\u003e HAVING Clause:---\u003c/h4\u003e\n ○ TheHAVINGclause is used with GROUP BY to filter groups based on\n aggregate function results.\u003cbr\u003e\n ○ It's similar to the WHERE clause but operates on grouped data.\u003cbr\u003e\n ○ Example: SELECT department, AVG(salary) FROM employees GROUP BY\n department HAVING AVG(salary) \u003e 50000;\n \n \u003ch4\u003eCombining GROUP BY and ORDER BY:---\u003c/h4\u003e\n ○ Youcanuseboth GROUPBYandORDERBYinthesamequery to control\n the order of grouped results.\u003cbr\u003e\n ○ Example: SELECT department, COUNT(*) FROM employees GROUP BY\n department ORDER BY COUNT(*) DESC;\n \n\u003ch3\u003e● AGGREGATE FUNCTIONS\u003c/h3\u003e\n These are used to perform calculations on groups of rows or entire result sets. They provide\n insights into data by summarising and processing information.\u003cbr\u003e\n \n\u003ch4\u003e Common Aggregate Functions:--\u003c/h4\u003e\nCOUNT(): Counts the number of rows in a group or result set.\u003cbr\u003e\n SUM(): Calculates the sum of numeric values in a group or result set.\u003cbr\u003e\n AVG():Computes the average of numeric values in a group or result set.\u003cbr\u003e\n MAX():Finds the maximum value in a group or result set.\u003cbr\u003e\n MIN():Retrieves the minimum value in a group or result set.\n\n \u003ch2\u003e3. DATA MANIPULATION LANGUAGE\u003c/h2\u003e\n Data Manipulation Language (DML) in SQL encompasses commands that manipulate data\n within a database. DML allows you to insert, update, and delete records, ensuring the\n accuracy and currency of your data.\n\n \u003ch3\u003e ● INSERT:\u003c/h3\u003e\n --\nThe INSERT statement adds new records to a table.\u003cbr\u003e\n Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2,\n ...);\u003cbr\u003e\n Example: INSERT INTO employees (first_name, last_name, salary) VALUES ('John',\n 'Doe', 50000);\n\n\u003ch3\u003e  ● UPDATE:--\u003c/h3\u003e\nThe UPDATE statement modifies existing records in a table.\u003cbr\u003e\n Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE\n condition;\u003cbr\u003e\n Example: UPDATE employees SET salary = 55000 WHERE first_name = 'John';\n \n \u003ch3\u003e● DELETE:--\u003c/h3\u003e\nThe DELETE statement removes records from a table.\u003cbr\u003e\n Syntax: DELETE FROM table_name WHERE condition;\u003cbr\u003e\n Example: DELETE FROM employees WHERE last_name = 'Doe';\n\n \u003ch2\u003e4. Data Control Language (DCL)\u003c/h2\u003e\n Data Control Language focuses on the management of access rights, permissions, and\n security-related aspects of a database system.\n DCL commands are used to control who can access the data, modify the data, or perform\n administrative tasks within a database.\n DCL is an important aspect of database security, ensuring that data remains protected and\n only authorised users have the necessary privileges.\n There are two main DCL commands in SQL: GRANT and REVOKE.\n\n \u003ch3\u003e1. GRANT:\u003c/h3\u003e\n The GRANT command is used to provide specific privileges or permissions to users or roles.\n Privileges can include the ability to perform various actions on tables, views, procedures,\n and other database objects.\n\n \u003ch4\u003eSyntax:\u003c/h4\u003e\n GRANTprivilege_type\u003cbr\u003e\n ONobject_name\u003cbr\u003e\n TO user_or_role;\u003cbr\u003e\n\n \u003ch4\u003eIn this syntax:\u003c/h4\u003e\n ● privilege_type refers to the specific privilege or permission being granted (e.g.,\n SELECT, INSERT, UPDATE, DELETE).\u003cbr\u003e\n ● object_name is the name of the database object (e.g., table, view) to which the\n privilege is being granted.\u003cbr\u003e\n ● user_or_role is the name of the user or role that is being granted the privilege.\u003cbr\u003e\n Example: Granting SELECT privilege on a table named \"Employees\" to a user named\n \"Analyst\":\u003cbr\u003e\n GRANTSELECTONEmployees TO Analyst;\n\n \u003ch3\u003e 2. REVOKE:\u003c/h3\u003e\n  The REVOKE command is used to remove or revoke specific privileges or permissions that\n have been previously granted to users or roles.\n\n \u003ch4\u003e Syntax:\u003c/h4\u003e\n  REVOKE privilege_type\u003cbr\u003e\n ONobject_name\u003cbr\u003e\n FROMuser_or_role;\n\n \u003ch4\u003e In this syntax:\u003c/h4\u003e\n  ● privilege_type is the privilege or permission being revoked.\u003cbr\u003e\n ● object_name is the name of the database object from which the privilege is being\n revoked.\u003cbr\u003e\n ● user_or_role is the name of the user or role from which the privilege is being\n revoked.\u003cbr\u003e\n Example: Revoking the SELECT privilege on the \"Employees\" table from the \"Analyst\" user:\u003cbr\u003e\n REVOKE SELECT ONEmployees FROM Analyst;\n\n \u003ch1\u003eDCL and Database Security:\u003c/h1\u003e\n DCL plays a crucial role in ensuring the security and integrity of a database system.\n By controlling access and permissions, DCL helps prevent unauthorised users from\n tampering with or accessing sensitive data. Proper use of GRANT and REVOKE commands\n ensures that only users who require specific privileges can perform certain actions on\n database objects.\n\n \u003ch2\u003e 5. Transaction Control Language (TCL)\u003c/h2\u003e\n  Transaction Control Language (TCL) deals with the management of transactions within a\n database.\n TCL commands are used to control the initiation, execution, and termination of transactions,\n which are sequences of one or more SQL statements that are executed as a single unit of\n work.\n Transactions ensure data consistency, integrity, and reliability in a database by grouping\n related operations together and either committing or rolling back changes based on the\n success or failure of those operations.\u003cbr\u003e\n\n  There are three main TCL commands in SQL: COMMIT, ROLLBACK, and SAVEPOINT.\n\n  \u003ch3\u003e1. COMMIT:\u003c/h3\u003e\n  The COMMIT command is used to permanently save the changes made during a\n transaction.\u003cbr\u003e\nIt makes all the changes applied to the database since the last COMMIT or ROLLBACK\n command permanent.\u003cbr\u003e\n Once a COMMIT is executed, the transaction is considered successful, and the changes are\n made permanent.\u003cbr\u003e\n\n Example: Committing changes made during a transaction:\u003cbr\u003e\n  \u003ch4\u003eUPDATE Employees\u003c/h4\u003e\n SET Salary = Salary * 1.10\u003cbr\u003e\n WHEREDepartment = 'Sales';\u003cbr\u003e\n COMMIT\n \n \u003ch3\u003e2. ROLLBACK:\u003c/h3\u003e\n  The ROLLBACK command is used to undo changes made during a transaction.\n It reverts all the changes applied to the database since the transaction began.\u003cbr\u003e\n ROLLBACK is typically used when an error occurs during the execution of a transaction,\n ensuring that the database remains in a consistent state. \u003cbr\u003e\n Example: Rolling back changes due to an error during a transaction:\u003cbr\u003e\n BEGIN;\u003cbr\u003e\n \n\u003ch4\u003e UPDATE Inventory\u003c/h4\u003e\n SET Quantity = Quantity- 10\u003cbr\u003e\n WHEREProductID = 101;-- An error occurs here\u003cbr\u003e\n ROLLBACK;\n\n \u003ch3\u003e3. SAVEPOINT:\u003c/h3\u003e\n  The SAVEPOINT command creates a named point within a transaction, allowing you to set a\n point to which you can later ROLLBACK if needed.\u003cbr\u003e\n SAVEPOINTs are useful when you want to undo part of a transaction while preserving other\n changes.\u003cbr\u003e\n Syntax: SAVEPOINT savepoint_name;\u003cbr\u003e\n Example: Using SAVEPOINT to create a point within a transaction:\u003cbr\u003e\n BEGIN;\n\n \u003ch4\u003eUPDATE Accounts\u003c/h4\u003e\n SET Balance = Balance- 100\u003cbr\u003e\n WHEREAccountID = 123;\u003cbr\u003e\nSAVEPOINT before_withdrawal;\u003cbr\u003e\n\n\n\u003ch4\u003e UPDATE Accounts\u003c/h4\u003e\n SET Balance = Balance + 100\u003cbr\u003e\n WHEREAccountID = 456;\u003cbr\u003e\n\n -- An error occurs here\n\n  ROLLBACK TObefore_withdrawal;\u003cbr\u003e\n  -- The first update is still applied\u003cbr\u003e\n COMMIT;\n\n\u003ch1\u003eTCL and Transaction Management:\u003c/h1\u003e\n  Transaction Control Language (TCL) commands are vital for managing the integrity and\n consistency of a database's data.\n They allow you to group related changes into transactions, and in the event of errors, either\n commit those changes or roll them back to maintain data integrity.\n TCL commands are used in combination with Data Manipulation Language (DML) and other\n SQL commands to ensure that the database remains in a reliable state despite unforeseen\n errors or issues.\n\n\n \u003ch1\u003eJOINS\u003c/h1\u003e\n  In a DBMS, a join is an operation that combines rows from two or more tables based on a\n related column between them.\u003cbr\u003e\n Joins are used to retrieve data from multiple tables by linking them together using a common\n key or column.\n\n \u003ch2\u003e Types of Joins:\n\u003c/h2\u003e\n1. Inner Join\u003cbr\u003e\n 2. Outer Join\u003cbr\u003e\n 3. Cross Join\u003cbr\u003e\n 4. Self Join\u003cbr\u003e\n\n \u003ch2\u003e 1) Inner Join\u003c/h2\u003e\n  An inner join combines data from two or more tables based on a specified condition, known\n as the join condition.\u003cbr\u003e\n The result of an inner join includes only the rows where the join condition is met in all\n participating tables.\u003cbr\u003e\n It essentially filters out non-matching rows and returns only the rows that have matching\n values in both tables.\n\n\u003ch3\u003e Syntax:\u003c/h3\u003e\u003cbr\u003e\n SELECT columns\u003cbr\u003e\n FROMtable1\u003cbr\u003e\n INNER JOIN table2\u003cbr\u003e\n ONtable1.column = table2.column;\n\n \u003ch3\u003e Here:\u003c/h3\u003e\n ● columns refers to the specific columns you want to retrieve from the tables.\u003cbr\u003e\n ● table1 and table2 are the names of the tables you are joining.\u003cbr\u003e\n ● columnis the common column used to match rows between the tables.\u003cbr\u003e\n ● TheONclause specifies the join condition, where you define how the tables are\n related.\n\n\n \u003ch2\u003e 2) Outer Join\u003c/h2\u003e\n  Outer joins combine data from two o rmore tables based on a specified condition, just like\n   inner joins.However,unlike inner joins,outer joins also include rows that do not have\n matching values in both tables.\n  Outer joins are particularly useful when you want to include data from one table even if there\n is no corresponding match in the other table.\n\u003ch3\u003eTypes:\u003c/h3\u003e\n\n\u003ch3\u003e1.Left Outer Join(LeftJoin):\u003c/h3\u003e\n A left outer join returns all the rows from the left table and the matching rows from the right\n table.\nIf there is no match in the right table, the result will still include the left table's row with NULL\n values in the right table's columns.\n\n \n\u003ch3\u003e 2. Right Outer Join (Right Join):\u003c/h3\u003e\n \n  A right outer join is similar to a left outer join, but it returns all rows from the right table and\n the matching rows from the left table.\u003cbr\u003e\n If there is no match in the left table, the result will still include the right table's row with NULL\n values in the left table's columns.\n\n \u003ch3\u003e 3.Full Outer Join(FullJoin):\u003c/h3\u003e\n  A full outer join returns all rows from both the left and right tables, including matches and\n non-matches.\u003cbr\u003e\n If there's no match,NULL values appear in columns from the table where there's no\n corresponding value\n\n\n \u003ch3\u003e 3) Cross Join:\u003c/h3\u003e\n  A cross join, also known as a Cartesian product, is a type of join operation in a Database\n Management System (DBMS) that combines every row from one table with every row from\n another table.\u003cbr\u003e\n Unlike other join types, a cross join does not require a specific condition to match rows\n between the tables. Instead, it generates a result set that contains all possible combinations\n of rows from both tables.\u003cbr\u003e\n Cross joins can lead to a large result set, especially when the participating tables have many\n rows.\n\n \u003ch4\u003e Syntax:\u003c/h4\u003e\n  SELECT columns\u003cbr\u003e\n FROM table1\u003cbr\u003e\n CROSS JOIN table2;\n\n\u003ch3\u003e 4) Self Join:\u003c/h3\u003e\n A self join involves joining a table with itself.\n  This technique is useful when at able contains hierarchical or related data and you need to\n compare or analyse rows within the same table.\u003cbr\u003e\n Self joins are commonly used to find relationships, hierarchies, or patterns within a single\n table.\u003cbr\u003e\n In a self join, you treat the table as if it were two separate tables, referring to them with\n different aliases.\n\n\n\u003ch1\u003eSET OPERATIONS\u003c/h1\u003e\nSet operations in SQL are used to combine or manipulate the result sets of multiple SELECT\n queries.\u003cbr\u003e\n They allow you to perform operations similar to those in set theory, such as union,\n intersection, and difference, on the data retrieved from different tables or queries.\u003cbr\u003e\n Set operations provide powerful tools for managing and manipulating data, enabling you to\n analyse and combine information in various ways.\u003cbr\u003e\n \nThere are four primary set operations in SQL:\n   ● UNION\u003cbr\u003e\n ● INTERSECT\u003cbr\u003e\n ● EXCEPT (or MINUS)\u003cbr\u003e\n ● UNION ALL\n\n \u003ch3\u003e 1. UNION:\u003c/h3\u003e\n The UNION operator combines the result sets of two or more SELECT queries into a single\n result set.\u003cbr\u003e\n It removes duplicates by default, meaning that if there are identical rows in the result sets,\n only one instance of each row will appear in the final result.\u003cbr\u003e\n \n\u003ch3\u003e 2. INTERSECT:\u003c/h3\u003e\nThe INTERSECT operator returns the common rows that exist in the result sets of two or\n more SELECT queries.\u003cbr\u003e\n  It only returns distinct rows that appear in all result sets.\n\n\u003ch3\u003e3. EXCEPT (or MINUS):\u003c/h3\u003e\n The EXCEPT operator (also known as MINUS in some databases) returns the distinct rows\n that are present in the result set of the first SELECT query but not in the result set of the\n second SELECT query.\n \n  \n\n \u003ch3\u003e 4. UNION ALL:\u003c/h3\u003e\n The UNION ALL operator performs the same function as the UNION operator but does not\n remove duplicates from the result set. It simply concatenates all rows from the different\n result sets.\n\n\n\n \n \n \n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchhaya03%2Fsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchhaya03%2Fsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchhaya03%2Fsql/lists"}