CREATE TABLE Orders (
ID INT PRIMARY KEY,
OrderDetails XML
);
Now, insert XML data:
INSERT INTO Orders (ID, OrderDetails)
VALUES (1, '<Order><Product>Laptop</Product><Price>1000</Price></Order>');
---
๐น Querying XML Data
To extract XML values, use the
.value() function: SELECT OrderDetails.value('(/Order/Product)[1]', 'NVARCHAR(50)') AS Product
FROM Orders;โ๏ธ Extracts the Product name from XML.
---
## ๐น Converting Table Data to JSON & XML
โ Convert Table to JSON
SELECT ID, Name FROM Customers
FOR JSON AUTO;
โ๏ธ Converts table rows into JSON format.
---
โ Convert Table to XML
SELECT ID, Name FROM Customers
FOR XML AUTO;
โ๏ธ Converts table rows into XML format.
---
๐น Summary of Today's Topics
| Concept | Key Takeaways |
|------------|-------------------|
| PIVOT | Converts rows into columns for summary reports. |
| UNPIVOT | Converts columns back into rows for data normalization. |
| JSON in SQL | Stores and queries structured data in JSON format. |
| XML in SQL | Stores and retrieves hierarchical data using XML. |
---
๐น Your Task for Today
โ Practice pivoting and unpivoting a sample dataset.
โ Store and query JSON data in a SQL table.
โ Store and query XML data in a SQL table.
---
๐ก Whatโs Next?
Tomorrow, we will learn Stored Procedures, Functions, and Triggers in SQL. Stay tuned! ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if you're enjoying this SQL series! ๐
Day 27: Writing Stored Procedures and Functions & Automating Processes with Triggers ๐
Welcome to Day 27 of your SQL journey! Today, we will learn:
โ๏ธ Stored Procedures โ Predefined SQL code that can be executed multiple times.
โ๏ธ Functions โ SQL code that returns a single value or table.
โ๏ธ Triggers โ Automated actions that execute when a certain event occurs.
Letโs break these down step by step! ๐
---
๐น Part 1: Writing Stored Procedures
โ What is a Stored Procedure?
A Stored Procedure is a set of SQL statements stored in the database that can be executed whenever needed.
๐น Why Use Stored Procedures?
โ๏ธ Reusability โ Write once, use multiple times.
โ๏ธ Security โ Prevent SQL injection.
โ๏ธ Performance โ Optimized query execution.
---
๐น Creating a Simple Stored Procedure
Letโs create a stored procedure to retrieve all customers from a Customers table.
๐น How to Execute a Stored Procedure?
โ๏ธ The procedure fetches all customer records when executed.
---
๐น Stored Procedure with Parameters
Letโs create a procedure to get customers from a specific country.
๐น Execute with a Parameter
โ๏ธ This retrieves all customers from the USA.
---
๐น Stored Procedure with Output Parameter
Stored procedures can return values using output parameters.
๐น Execute and Get the Output
โ๏ธ This counts and prints the total number of customers.
---
๐น Part 2: Writing Functions in SQL
โ What is a Function?
A Function in SQL is a reusable block of code that returns a value.
๐น Types of Functions in SQL:
1๏ธโฃ Scalar Functions โ Return a single value.
2๏ธโฃ Table-Valued Functions โ Return a table.
---
๐น Creating a Scalar Function
Letโs create a function that calculates the total price after tax for a given price.
๐น Using the Function
โ๏ธ If the input is 100, the output will be 110.
---
๐น Creating a Table-Valued Function
Letโs create a function that returns customers from a given country.
๐น Using the Function
โ๏ธ This retrieves all USA customers in a tabular format.
---
๐น Part 3: Automating Processes with Triggers
โ What is a Trigger?
A Trigger is a special type of stored procedure that executes automatically when a specific action occurs in the database.
๐น Why Use Triggers?
โ๏ธ Enforce Business Rules โ Prevent invalid data entry.
โ๏ธ Maintain Audit Logs โ Track changes automatically.
โ๏ธ Automate Actions โ Example: Send a notification when a new record is inserted.
---
๐น Types of Triggers in SQL
1๏ธโฃ AFTER Triggers โ Execute after an INSERT, UPDATE, or DELETE operation.
2๏ธโฃ INSTEAD OF Triggers โ Replace an operation with custom logic.
---
๐น Creating an AFTER INSERT Trigger
Letโs create a trigger that logs new customer entries in an audit table.
Now, letโs create the trigger:
Welcome to Day 27 of your SQL journey! Today, we will learn:
โ๏ธ Stored Procedures โ Predefined SQL code that can be executed multiple times.
โ๏ธ Functions โ SQL code that returns a single value or table.
โ๏ธ Triggers โ Automated actions that execute when a certain event occurs.
Letโs break these down step by step! ๐
---
๐น Part 1: Writing Stored Procedures
โ What is a Stored Procedure?
A Stored Procedure is a set of SQL statements stored in the database that can be executed whenever needed.
๐น Why Use Stored Procedures?
โ๏ธ Reusability โ Write once, use multiple times.
โ๏ธ Security โ Prevent SQL injection.
โ๏ธ Performance โ Optimized query execution.
---
๐น Creating a Simple Stored Procedure
Letโs create a stored procedure to retrieve all customers from a Customers table.
CREATE PROCEDURE GetAllCustomers
AS
BEGIN
SELECT * FROM Customers;
END;
๐น How to Execute a Stored Procedure?
EXEC GetAllCustomers;
โ๏ธ The procedure fetches all customer records when executed.
---
๐น Stored Procedure with Parameters
Letโs create a procedure to get customers from a specific country.
CREATE PROCEDURE GetCustomersByCountry
@Country NVARCHAR(50)
AS
BEGIN
SELECT * FROM Customers WHERE Country = @Country;
END;
๐น Execute with a Parameter
EXEC GetCustomersByCountry 'USA';
โ๏ธ This retrieves all customers from the USA.
---
๐น Stored Procedure with Output Parameter
Stored procedures can return values using output parameters.
CREATE PROCEDURE GetTotalCustomers
@Total INT OUTPUT
AS
BEGIN
SELECT @Total = COUNT(*) FROM Customers;
END;
๐น Execute and Get the Output
DECLARE @TotalCustomers INT;
EXEC GetTotalCustomers @TotalCustomers OUTPUT;
PRINT @TotalCustomers;
โ๏ธ This counts and prints the total number of customers.
---
๐น Part 2: Writing Functions in SQL
โ What is a Function?
A Function in SQL is a reusable block of code that returns a value.
๐น Types of Functions in SQL:
1๏ธโฃ Scalar Functions โ Return a single value.
2๏ธโฃ Table-Valued Functions โ Return a table.
---
๐น Creating a Scalar Function
Letโs create a function that calculates the total price after tax for a given price.
CREATE FUNCTION CalculateTax(@Price DECIMAL(10,2))
RETURNS DECIMAL(10,2)
AS
BEGIN
RETURN @Price * 1.10; -- Adding 10% tax
END;
๐น Using the Function
SELECT dbo.CalculateTax(100) AS PriceWithTax;
โ๏ธ If the input is 100, the output will be 110.
---
๐น Creating a Table-Valued Function
Letโs create a function that returns customers from a given country.
CREATE FUNCTION GetCustomersFromCountry(@Country NVARCHAR(50))
RETURNS TABLE
AS
RETURN
(
SELECT * FROM Customers WHERE Country = @Country
);
๐น Using the Function
SELECT * FROM dbo.GetCustomersFromCountry('USA');โ๏ธ This retrieves all USA customers in a tabular format.
---
๐น Part 3: Automating Processes with Triggers
โ What is a Trigger?
A Trigger is a special type of stored procedure that executes automatically when a specific action occurs in the database.
๐น Why Use Triggers?
โ๏ธ Enforce Business Rules โ Prevent invalid data entry.
โ๏ธ Maintain Audit Logs โ Track changes automatically.
โ๏ธ Automate Actions โ Example: Send a notification when a new record is inserted.
---
๐น Types of Triggers in SQL
1๏ธโฃ AFTER Triggers โ Execute after an INSERT, UPDATE, or DELETE operation.
2๏ธโฃ INSTEAD OF Triggers โ Replace an operation with custom logic.
---
๐น Creating an AFTER INSERT Trigger
Letโs create a trigger that logs new customer entries in an audit table.
CREATE TABLE CustomerLog (
LogID INT IDENTITY PRIMARY KEY,
CustomerID INT,
ActionTaken NVARCHAR(50),
ActionDate DATETIME DEFAULT GETDATE()
);
Now, letโs create the trigger:
CREATE TRIGGER trg_AfterCustomerInsert
ON Customers
AFTER INSERT
AS
BEGIN
INSERT INTO CustomerLog (CustomerID, ActionTaken)
SELECT ID, 'Inserted' FROM INSERTED;
END;
๐1
๐น How it Works?
โ๏ธ When a new customer is added, an entry is automatically made in CustomerLog.
---
๐น Creating an AFTER UPDATE Trigger
Letโs create a trigger to track salary changes in an Employees table.
โ๏ธ INSERTED Table โ Holds new data after an update.
โ๏ธ DELETED Table โ Holds old data before the update.
---
๐น Creating an INSTEAD OF DELETE Trigger
Letโs prevent accidental deletion of employees by marking them as "Inactive" instead of deleting.
โ๏ธ Now, when someone tries to delete an employee, they are just marked as inactive instead.
---
๐น Summary of Todayโs Topics
| Concept | Key Takeaways |
|------------|-------------------|
| Stored Procedures | Predefined SQL queries that execute on demand. |
| Functions | Return a single value (scalar) or table (table-valued). |
| Triggers | Execute automatically when an INSERT, UPDATE, or DELETE happens. |
---
๐น Your Task for Today
โ Create a stored procedure to get customer orders.
โ Write a function to calculate discounts.
โ Create a trigger to track changes in a table.
---
๐ก Whatโs Next?
Tomorrow, we will explore Integrating SQL with Python, Power BI, and Tableau & SQL in Big Data (NoSQL). ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if you're enjoying this SQL series! ๐
โ๏ธ When a new customer is added, an entry is automatically made in CustomerLog.
---
๐น Creating an AFTER UPDATE Trigger
Letโs create a trigger to track salary changes in an Employees table.
CREATE TRIGGER trg_AfterSalaryUpdate
ON Employees
AFTER UPDATE
AS
BEGIN
IF UPDATE(Salary)
BEGIN
INSERT INTO SalaryAudit (EmployeeID, OldSalary, NewSalary, ChangeDate)
SELECT i.ID, d.Salary, i.Salary, GETDATE()
FROM INSERTED i
JOIN DELETED d ON i.ID = d.ID;
END
END;
โ๏ธ INSERTED Table โ Holds new data after an update.
โ๏ธ DELETED Table โ Holds old data before the update.
---
๐น Creating an INSTEAD OF DELETE Trigger
Letโs prevent accidental deletion of employees by marking them as "Inactive" instead of deleting.
CREATE TRIGGER trg_InsteadOfDelete
ON Employees
INSTEAD OF DELETE
AS
BEGIN
UPDATE Employees
SET IsActive = 0
WHERE ID IN (SELECT ID FROM DELETED);
END;
โ๏ธ Now, when someone tries to delete an employee, they are just marked as inactive instead.
---
๐น Summary of Todayโs Topics
| Concept | Key Takeaways |
|------------|-------------------|
| Stored Procedures | Predefined SQL queries that execute on demand. |
| Functions | Return a single value (scalar) or table (table-valued). |
| Triggers | Execute automatically when an INSERT, UPDATE, or DELETE happens. |
---
๐น Your Task for Today
โ Create a stored procedure to get customer orders.
โ Write a function to calculate discounts.
โ Create a trigger to track changes in a table.
---
๐ก Whatโs Next?
Tomorrow, we will explore Integrating SQL with Python, Power BI, and Tableau & SQL in Big Data (NoSQL). ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if you're enjoying this SQL series! ๐
Day 28: Integrating SQL with Other Tools & SQL in Big Data (NoSQL) ๐
Welcome to Day 28 of your SQL journey! Today, we will cover:
โ๏ธ How SQL integrates with other tools like Python, Power BI, and Tableau.
โ๏ธ SQL in Big Data โ Introduction to NoSQL databases.
Letโs break everything down step by step! ๐
---
๐น Part 1: Integrating SQL with Other Tools
SQL is often used in combination with other tools for data analysis, reporting, and visualization.
๐น Why Integrate SQL with Other Tools?
โ๏ธ Automate Data Extraction ๐ฅ
โ๏ธ Analyze Data in Python ๐
โ๏ธ Visualize Data in Power BI & Tableau ๐
---
๐น SQL with Python
Python is widely used for data analysis, machine learning, and automation. To connect Python with SQL, we use libraries like:
โ๏ธ sqlite3 โ For SQLite databases
โ๏ธ pyodbc โ For MS SQL Server
โ๏ธ mysql-connector-python โ For MySQL
โ๏ธ psycopg2 โ For PostgreSQL
๐น Connecting Python to SQL (Example: MySQL)
1๏ธโฃ Install MySQL Connector
2๏ธโฃ Connect Python to MySQL Database
โ๏ธ This connects Python to MySQL and fetches employee data.
---
๐น SQL with Power BI
Power BI is a powerful tool for data visualization and business intelligence.
### ๐น Steps to Connect SQL with Power BI
1๏ธโฃ Open Power BI
2๏ธโฃ Click on โGet Dataโ โ Select โSQL Serverโ
3๏ธโฃ Enter Server Name & Database Name
4๏ธโฃ Load the Data and start creating reports!
---
๐น SQL with Tableau
Tableau is another great tool for data visualization.
๐น Steps to Connect SQL with Tableau
1๏ธโฃ Open Tableau
2๏ธโฃ Click on โConnectโ โ Choose your SQL Database
3๏ธโฃ Enter Server Credentials & Connect
4๏ธโฃ Drag & Drop Tables to build interactive reports!
---
๐น Part 2: SQL in Big Data & Introduction to NoSQL
๐น What is Big Data?
Big Data refers to huge volumes of structured and unstructured data that traditional SQL databases cannot handle efficiently.
๐น SQL vs NoSQL
| Feature | SQL (Relational DB) | NoSQL (Non-Relational DB) |
|---------|------------------|----------------------|
| Data Structure | Tables (Rows & Columns) | Documents, Key-Value, Graphs, etc. |
| Schema | Fixed Schema | Flexible Schema |
| Scalability | Vertical Scaling | Horizontal Scaling |
| Transactions | Follows ACID | BASE (Eventual Consistency) |
| Example DBs | MySQL, PostgreSQL, SQL Server | MongoDB, Firebase, Cassandra |
---
๐น NoSQL Databases Overview
There are four types of NoSQL databases:
1๏ธโฃ Document Databases (MongoDB, CouchDB) โ Store data as JSON-like documents.
2๏ธโฃ Key-Value Stores (Redis, DynamoDB) โ Store data as key-value pairs.
3๏ธโฃ Column-Family Stores (Cassandra, HBase) โ Store data in columns instead of rows.
4๏ธโฃ Graph Databases (Neo4j) โ Store relationships between data nodes.
---
๐น SQL vs NoSQL: When to Use What?
โ๏ธ Use SQL when:
- Your data has a structured format.
- You need ACID transactions (Banking, ERP).
โ๏ธ Use NoSQL when:
- Your data is unstructured (JSON, images, logs).
- You need high-speed scaling (Social Media, IoT).
---
๐น Summary of Todayโs Topics
| Concept | Key Takeaways |
|------------|-------------------|
| SQL with Python | Automates data analysis and machine learning. |
| SQL with Power BI & Tableau | Helps create business reports and dashboards. |
| NoSQL Databases | Handle Big Data and flexible schema structures. |
| SQL vs NoSQL | SQL is structured; NoSQL is flexible and scalable. |
---
๐น Your Task for Today
โ Connect SQL with Python & Fetch Data
โ Load SQL Data in Power BI or Tableau
โ Explore NoSQL by installing MongoDB & running basic queries
---
Welcome to Day 28 of your SQL journey! Today, we will cover:
โ๏ธ How SQL integrates with other tools like Python, Power BI, and Tableau.
โ๏ธ SQL in Big Data โ Introduction to NoSQL databases.
Letโs break everything down step by step! ๐
---
๐น Part 1: Integrating SQL with Other Tools
SQL is often used in combination with other tools for data analysis, reporting, and visualization.
๐น Why Integrate SQL with Other Tools?
โ๏ธ Automate Data Extraction ๐ฅ
โ๏ธ Analyze Data in Python ๐
โ๏ธ Visualize Data in Power BI & Tableau ๐
---
๐น SQL with Python
Python is widely used for data analysis, machine learning, and automation. To connect Python with SQL, we use libraries like:
โ๏ธ sqlite3 โ For SQLite databases
โ๏ธ pyodbc โ For MS SQL Server
โ๏ธ mysql-connector-python โ For MySQL
โ๏ธ psycopg2 โ For PostgreSQL
๐น Connecting Python to SQL (Example: MySQL)
1๏ธโฃ Install MySQL Connector
pip install mysql-connector-python
2๏ธโฃ Connect Python to MySQL Database
import mysql.connector
# Connect to database
conn = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="company"
)
cursor = conn.cursor()
# Execute a query
cursor.execute("SELECT * FROM Employees")
# Fetch and display data
for row in cursor.fetchall():
print(row)
# Close the connection
conn.close()
โ๏ธ This connects Python to MySQL and fetches employee data.
---
๐น SQL with Power BI
Power BI is a powerful tool for data visualization and business intelligence.
### ๐น Steps to Connect SQL with Power BI
1๏ธโฃ Open Power BI
2๏ธโฃ Click on โGet Dataโ โ Select โSQL Serverโ
3๏ธโฃ Enter Server Name & Database Name
4๏ธโฃ Load the Data and start creating reports!
---
๐น SQL with Tableau
Tableau is another great tool for data visualization.
๐น Steps to Connect SQL with Tableau
1๏ธโฃ Open Tableau
2๏ธโฃ Click on โConnectโ โ Choose your SQL Database
3๏ธโฃ Enter Server Credentials & Connect
4๏ธโฃ Drag & Drop Tables to build interactive reports!
---
๐น Part 2: SQL in Big Data & Introduction to NoSQL
๐น What is Big Data?
Big Data refers to huge volumes of structured and unstructured data that traditional SQL databases cannot handle efficiently.
๐น SQL vs NoSQL
| Feature | SQL (Relational DB) | NoSQL (Non-Relational DB) |
|---------|------------------|----------------------|
| Data Structure | Tables (Rows & Columns) | Documents, Key-Value, Graphs, etc. |
| Schema | Fixed Schema | Flexible Schema |
| Scalability | Vertical Scaling | Horizontal Scaling |
| Transactions | Follows ACID | BASE (Eventual Consistency) |
| Example DBs | MySQL, PostgreSQL, SQL Server | MongoDB, Firebase, Cassandra |
---
๐น NoSQL Databases Overview
There are four types of NoSQL databases:
1๏ธโฃ Document Databases (MongoDB, CouchDB) โ Store data as JSON-like documents.
2๏ธโฃ Key-Value Stores (Redis, DynamoDB) โ Store data as key-value pairs.
3๏ธโฃ Column-Family Stores (Cassandra, HBase) โ Store data in columns instead of rows.
4๏ธโฃ Graph Databases (Neo4j) โ Store relationships between data nodes.
---
๐น SQL vs NoSQL: When to Use What?
โ๏ธ Use SQL when:
- Your data has a structured format.
- You need ACID transactions (Banking, ERP).
โ๏ธ Use NoSQL when:
- Your data is unstructured (JSON, images, logs).
- You need high-speed scaling (Social Media, IoT).
---
๐น Summary of Todayโs Topics
| Concept | Key Takeaways |
|------------|-------------------|
| SQL with Python | Automates data analysis and machine learning. |
| SQL with Power BI & Tableau | Helps create business reports and dashboards. |
| NoSQL Databases | Handle Big Data and flexible schema structures. |
| SQL vs NoSQL | SQL is structured; NoSQL is flexible and scalable. |
---
๐น Your Task for Today
โ Connect SQL with Python & Fetch Data
โ Load SQL Data in Power BI or Tableau
โ Explore NoSQL by installing MongoDB & running basic queries
---
๐1
๐ก Whatโs Next?
Tomorrow, we will focus on Query Performance Tuning & SQL Optimization Techniques! ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if you're enjoying this SQL series! ๐
Tomorrow, we will focus on Query Performance Tuning & SQL Optimization Techniques! ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if you're enjoying this SQL series! ๐
Day 29: Query Performance Tuning โ Optimize Your SQL Queries ๐
Welcome to Day 29 of your SQL journey! Today, weโll cover:
โ๏ธ How to optimize SQL queries for faster execution.
โ๏ธ Common performance tuning techniques to improve efficiency.
โ๏ธ Best practices for writing optimized SQL queries.
By the end of this lesson, youโll be able to write SQL queries that run faster and handle large datasets efficiently!
---
๐น Why is Query Performance Tuning Important?
When working with databases, slow queries can affect application performance. Optimizing queries helps:
โ๏ธ Reduce execution time โณ
โ๏ธ Handle large amounts of data efficiently ๐
โ๏ธ Improve database performance ๐
---
๐น 1. Use SELECT Only What You Need
โ Bad Query: Selecting All Columns
โ๏ธ This fetches all columns from the table, even if you need only a few.
โ Optimized Query: Select Specific Columns
โ๏ธ This improves performance by fetching only the required data.
---
๐น 2. Use Proper Indexing
Indexes speed up searches by allowing the database to locate data faster.
How to Create an Index?
โ๏ธ This index speeds up queries filtering by Name.
Using Index in Query
โ๏ธ The database will use the index instead of scanning the entire table.
---
๐น 3. Avoid Using Functions on Indexed Columns
Using functions prevents indexes from working efficiently.
โ Bad Query: Function on Indexed Column
โ๏ธ The database has to apply LOWER() on every row, making it slow.
โ Optimized Query: Avoid Functions on Indexed Column
โ๏ธ This allows the index to be used directly, improving speed.
---
๐น 4. Use Joins Efficiently
When joining tables, use INNER JOIN instead of CROSS JOIN if possible.
โ Bad Query: CROSS JOIN (Slow)
โ๏ธ CROSS JOIN generates all possible combinations, leading to performance issues.
โ Optimized Query: Use INNER JOIN
โ๏ธ INNER JOIN fetches only matching rows, reducing unnecessary computations.
---
๐น 5. Use EXISTS Instead of IN for Subqueries
When checking if a record exists in another table, EXISTS is usually faster than IN.
โ Bad Query: Using IN (Slow for Large Data)
โ๏ธ IN executes the subquery multiple times, making it slower.
โ Optimized Query: Using EXISTS
โ๏ธ EXISTS stops checking once a match is found, making it more efficient.
---
๐น 6. Optimize ORDER BY with Indexing
Sorting large datasets can be slow. Adding an index on the ORDER BY column improves performance.
Creating an Index on Sorted Column
Optimized Query
โ๏ธ The database uses the index instead of sorting all rows manually.
---
# ๐น 7. Limit Data Retrieval Using LIMIT or TOP
Fetching too much data slows down performance. Use LIMIT (MySQL, PostgreSQL) or TOP (SQL Server) to limit results.
Optimized Query: Fetch Only First 10 Records
โ๏ธ This ensures only required rows are fetched, making queries faster.
---
๐น 8. Use Proper Data Types
Choosing the right data type saves storage and speeds up queries.
Welcome to Day 29 of your SQL journey! Today, weโll cover:
โ๏ธ How to optimize SQL queries for faster execution.
โ๏ธ Common performance tuning techniques to improve efficiency.
โ๏ธ Best practices for writing optimized SQL queries.
By the end of this lesson, youโll be able to write SQL queries that run faster and handle large datasets efficiently!
---
๐น Why is Query Performance Tuning Important?
When working with databases, slow queries can affect application performance. Optimizing queries helps:
โ๏ธ Reduce execution time โณ
โ๏ธ Handle large amounts of data efficiently ๐
โ๏ธ Improve database performance ๐
---
๐น 1. Use SELECT Only What You Need
โ Bad Query: Selecting All Columns
SELECT * FROM Employees;
โ๏ธ This fetches all columns from the table, even if you need only a few.
โ Optimized Query: Select Specific Columns
SELECT EmployeeID, Name, Salary FROM Employees;
โ๏ธ This improves performance by fetching only the required data.
---
๐น 2. Use Proper Indexing
Indexes speed up searches by allowing the database to locate data faster.
How to Create an Index?
CREATE INDEX idx_employee_name ON Employees(Name);
โ๏ธ This index speeds up queries filtering by Name.
Using Index in Query
SELECT * FROM Employees WHERE Name = 'John Doe';
โ๏ธ The database will use the index instead of scanning the entire table.
---
๐น 3. Avoid Using Functions on Indexed Columns
Using functions prevents indexes from working efficiently.
โ Bad Query: Function on Indexed Column
SELECT * FROM Employees WHERE LOWER(Name) = 'john doe';
โ๏ธ The database has to apply LOWER() on every row, making it slow.
โ Optimized Query: Avoid Functions on Indexed Column
SELECT * FROM Employees WHERE Name = 'John Doe';
โ๏ธ This allows the index to be used directly, improving speed.
---
๐น 4. Use Joins Efficiently
When joining tables, use INNER JOIN instead of CROSS JOIN if possible.
โ Bad Query: CROSS JOIN (Slow)
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders, Customers
WHERE Orders.CustomerID = Customers.CustomerID;
โ๏ธ CROSS JOIN generates all possible combinations, leading to performance issues.
โ Optimized Query: Use INNER JOIN
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
โ๏ธ INNER JOIN fetches only matching rows, reducing unnecessary computations.
---
๐น 5. Use EXISTS Instead of IN for Subqueries
When checking if a record exists in another table, EXISTS is usually faster than IN.
โ Bad Query: Using IN (Slow for Large Data)
SELECT * FROM Employees
WHERE EmployeeID IN (SELECT EmployeeID FROM Salaries WHERE Salary > 50000);
โ๏ธ IN executes the subquery multiple times, making it slower.
โ Optimized Query: Using EXISTS
SELECT * FROM Employees
WHERE EXISTS (SELECT 1 FROM Salaries WHERE Salaries.EmployeeID = Employees.EmployeeID AND Salary > 50000);
โ๏ธ EXISTS stops checking once a match is found, making it more efficient.
---
๐น 6. Optimize ORDER BY with Indexing
Sorting large datasets can be slow. Adding an index on the ORDER BY column improves performance.
Creating an Index on Sorted Column
CREATE INDEX idx_salary ON Employees(Salary);
Optimized Query
SELECT * FROM Employees ORDER BY Salary;
โ๏ธ The database uses the index instead of sorting all rows manually.
---
# ๐น 7. Limit Data Retrieval Using LIMIT or TOP
Fetching too much data slows down performance. Use LIMIT (MySQL, PostgreSQL) or TOP (SQL Server) to limit results.
Optimized Query: Fetch Only First 10 Records
SELECT * FROM Employees LIMIT 10; -- MySQL, PostgreSQL
SELECT TOP 10 * FROM Employees; -- SQL Server
โ๏ธ This ensures only required rows are fetched, making queries faster.
---
๐น 8. Use Proper Data Types
Choosing the right data type saves storage and speeds up queries.
๐2โค1
โ Bad Practice: Using Large Data Types
โ๏ธ VARCHAR(500) is too large for names.
โ Optimized Table: Use Smaller Data Types
โ๏ธ TINYINT (1 byte) instead of INT (4 bytes) for Age saves space.
---
๐น 9. Use Partitioning for Large Tables
Partitioning splits a large table into smaller parts for faster queries.
Example: Partitioning a Sales Table by Year
โ๏ธ This makes it faster to search for specific years.
---
๐น 10. Use Query Execution Plan for Optimization
EXPLAIN (MySQL, PostgreSQL) or EXECUTION PLAN (SQL Server) helps analyze how a query runs.
How to Use EXPLAIN?
โ๏ธ It shows if indexes are used and where the query is slow.
---
๐น Summary of SQL Performance Tuning Techniques
| Technique | Benefit |
|--------------|------------|
| Select Only Needed Columns | Reduces memory usage |
| Use Indexing | Speeds up searches |
| Avoid Functions on Indexed Columns | Allows index usage |
| Optimize Joins | Reduces unnecessary computations |
| Use EXISTS Instead of IN | Faster subqueries |
| Optimize ORDER BY | Uses indexes for sorting |
| Use LIMIT/TOP | Fetches only required rows |
| Choose Proper Data Types | Saves storage space |
| Use Partitioning | Speeds up queries on large tables |
| Analyze Execution Plan | Finds slow queries |
---
๐น Your Task for Today
โ Optimize a slow query using indexing or LIMIT.
โ Use EXPLAIN to analyze your query performance.
โ Try EXISTS instead of IN for a subquery.
---
๐ก Whatโs Next?
Tomorrow is the final day โ Day 30: Final Review & SQL Projects! ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if this helped you! ๐
CREATE TABLE Users (
UserID BIGINT,
Name VARCHAR(500),
Age INT
);
โ๏ธ VARCHAR(500) is too large for names.
โ Optimized Table: Use Smaller Data Types
CREATE TABLE Users (
UserID INT,
Name VARCHAR(100),
Age TINYINT
);
โ๏ธ TINYINT (1 byte) instead of INT (4 bytes) for Age saves space.
---
๐น 9. Use Partitioning for Large Tables
Partitioning splits a large table into smaller parts for faster queries.
Example: Partitioning a Sales Table by Year
CREATE TABLE Sales (
SaleID INT,
SaleDate DATE,
Amount DECIMAL(10,2)
) PARTITION BY RANGE (YEAR(SaleDate));
โ๏ธ This makes it faster to search for specific years.
---
๐น 10. Use Query Execution Plan for Optimization
EXPLAIN (MySQL, PostgreSQL) or EXECUTION PLAN (SQL Server) helps analyze how a query runs.
How to Use EXPLAIN?
EXPLAIN SELECT * FROM Employees WHERE Name = 'John Doe';
โ๏ธ It shows if indexes are used and where the query is slow.
---
๐น Summary of SQL Performance Tuning Techniques
| Technique | Benefit |
|--------------|------------|
| Select Only Needed Columns | Reduces memory usage |
| Use Indexing | Speeds up searches |
| Avoid Functions on Indexed Columns | Allows index usage |
| Optimize Joins | Reduces unnecessary computations |
| Use EXISTS Instead of IN | Faster subqueries |
| Optimize ORDER BY | Uses indexes for sorting |
| Use LIMIT/TOP | Fetches only required rows |
| Choose Proper Data Types | Saves storage space |
| Use Partitioning | Speeds up queries on large tables |
| Analyze Execution Plan | Finds slow queries |
---
๐น Your Task for Today
โ Optimize a slow query using indexing or LIMIT.
โ Use EXPLAIN to analyze your query performance.
โ Try EXISTS instead of IN for a subquery.
---
๐ก Whatโs Next?
Tomorrow is the final day โ Day 30: Final Review & SQL Projects! ๐
๐ฌ Comment below if you have questions! Like โค๏ธ & Share if this helped you! ๐
๐1
Day 30: Final Review & SQL Projects โ Apply Your Knowledge! ๐
๐ Congratulations! You've reached the final day of your 30-day SQL journey. Today, weโll:
โ Review all key SQL concepts learned over the past 30 days.
โ Work on real-world SQL projects to apply your skills.
โ Solve case studies & challenges to test your knowledge.
By the end of this lesson, youโll be confident in writing SQL queries and solving real-world data problems!
---
๐น Quick Recap: Key SQL Concepts You Learned
| Topic | Key Learnings |
|-----------|------------------|
| Day 1-5: Basics | SQL syntax, SELECT, WHERE, ORDER BY, GROUP BY, HAVING, Aggregate Functions |
| Day 6-10: Joins & Subqueries | INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, Subqueries |
| Day 11-15: Advanced Queries | Common Table Expressions (CTEs), Window Functions, Case Statements |
| Day 16-20: Views, Transactions, Indexing | Creating Views, Indexing, Transactions & ACID properties, Error Handling |
| Day 21-25: Database Design & Security | Normalization (1NF, 2NF, 3NF, BCNF), Constraints, Backup & Restore, Role-Based Permissions |
| Day 26-29: Performance Optimization | Pivoting, JSON/XML in SQL, Stored Procedures, Triggers, Query Performance Tuning |
If youโve completed all the lessons, you now have a solid SQL foundation! ๐
---
๐น Real-World SQL Projects & Case Studies
Now, letโs apply what youโve learned by working on SQL projects.
Project 1: Analyzing Sales Data ๐
Scenario: You work for an e-commerce company, and management wants to analyze sales performance.
Dataset: Sales Table
| SaleID | Date | CustomerID | ProductID | Quantity | Price | TotalAmount |
|--------|------|------------|------------|---------|------|------------|
| 101 | 2024-01-10 | 1 | 1001 | 2 | 500 | 1000 |
| 102 | 2024-01-11 | 2 | 1002 | 1 | 300 | 300 |
| 103 | 2024-01-12 | 1 | 1003 | 5 | 200 | 1000 |
Tasks:
โ๏ธ Find total sales per customer
โ๏ธ Get the top 5 products by sales revenue
โ๏ธ Find the total revenue for each month
โ๏ธ Find customers who made purchases in January but not in February
๐ฏ Objective: Gain hands-on experience analyzing business sales data.
---
Project 2: Building a Reporting Dashboard ๐
๐น Tools: Use SQL with Power BI, Tableau, or Python (Pandas & Matplotlib)
โ๏ธ Step 1: Write SQL queries to extract data from your database.
โ๏ธ Step 2: Connect SQL with Power BI/Tableau to create reports.
โ๏ธ Step 3: Build visualizations (e.g., bar charts, trend lines, KPIs).
๐ฏ Objective: Convert raw data into actionable insights for decision-making.
---
Project 3: Employee Management System
Scenario: HR wants to track employee performance and salaries.
Dataset: Employees Table
| EmpID | Name | Department | Salary | JoinDate |
|--------|------|------------|--------|---------|
| 1 | Alice | IT | 80000 | 2021-05-10 |
| 2 | Bob | HR | 60000 | 2022-08-15 |
| 3 | Charlie | IT | 90000 | 2019-12-01 |
Tasks:
โ๏ธ Find average salary by department
โ๏ธ List employees who have been with the company for more than 3 years
โ๏ธ Create a stored procedure to update salaries based on department
๐ฏ Objective: Learn how to manage employee data using SQL.
---
๐ Congratulations! You've reached the final day of your 30-day SQL journey. Today, weโll:
โ Review all key SQL concepts learned over the past 30 days.
โ Work on real-world SQL projects to apply your skills.
โ Solve case studies & challenges to test your knowledge.
By the end of this lesson, youโll be confident in writing SQL queries and solving real-world data problems!
---
๐น Quick Recap: Key SQL Concepts You Learned
| Topic | Key Learnings |
|-----------|------------------|
| Day 1-5: Basics | SQL syntax, SELECT, WHERE, ORDER BY, GROUP BY, HAVING, Aggregate Functions |
| Day 6-10: Joins & Subqueries | INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, Subqueries |
| Day 11-15: Advanced Queries | Common Table Expressions (CTEs), Window Functions, Case Statements |
| Day 16-20: Views, Transactions, Indexing | Creating Views, Indexing, Transactions & ACID properties, Error Handling |
| Day 21-25: Database Design & Security | Normalization (1NF, 2NF, 3NF, BCNF), Constraints, Backup & Restore, Role-Based Permissions |
| Day 26-29: Performance Optimization | Pivoting, JSON/XML in SQL, Stored Procedures, Triggers, Query Performance Tuning |
If youโve completed all the lessons, you now have a solid SQL foundation! ๐
---
๐น Real-World SQL Projects & Case Studies
Now, letโs apply what youโve learned by working on SQL projects.
Project 1: Analyzing Sales Data ๐
Scenario: You work for an e-commerce company, and management wants to analyze sales performance.
Dataset: Sales Table
| SaleID | Date | CustomerID | ProductID | Quantity | Price | TotalAmount |
|--------|------|------------|------------|---------|------|------------|
| 101 | 2024-01-10 | 1 | 1001 | 2 | 500 | 1000 |
| 102 | 2024-01-11 | 2 | 1002 | 1 | 300 | 300 |
| 103 | 2024-01-12 | 1 | 1003 | 5 | 200 | 1000 |
Tasks:
โ๏ธ Find total sales per customer
SELECT CustomerID, SUM(TotalAmount) AS TotalSpent
FROM Sales
GROUP BY CustomerID
ORDER BY TotalSpent DESC;
โ๏ธ Get the top 5 products by sales revenue
SELECT ProductID, SUM(TotalAmount) AS Revenue
FROM Sales
GROUP BY ProductID
ORDER BY Revenue DESC
LIMIT 5;
โ๏ธ Find the total revenue for each month
SELECT DATE_FORMAT(Date, '%Y-%m') AS Month, SUM(TotalAmount) AS Revenue
FROM Sales
GROUP BY Month
ORDER BY Month;
โ๏ธ Find customers who made purchases in January but not in February
SELECT DISTINCT CustomerID
FROM Sales
WHERE DATE_FORMAT(Date, '%Y-%m') = '2024-01'
AND CustomerID NOT IN (
SELECT DISTINCT CustomerID FROM Sales
WHERE DATE_FORMAT(Date, '%Y-%m') = '2024-02'
);
๐ฏ Objective: Gain hands-on experience analyzing business sales data.
---
Project 2: Building a Reporting Dashboard ๐
๐น Tools: Use SQL with Power BI, Tableau, or Python (Pandas & Matplotlib)
โ๏ธ Step 1: Write SQL queries to extract data from your database.
โ๏ธ Step 2: Connect SQL with Power BI/Tableau to create reports.
โ๏ธ Step 3: Build visualizations (e.g., bar charts, trend lines, KPIs).
๐ฏ Objective: Convert raw data into actionable insights for decision-making.
---
Project 3: Employee Management System
Scenario: HR wants to track employee performance and salaries.
Dataset: Employees Table
| EmpID | Name | Department | Salary | JoinDate |
|--------|------|------------|--------|---------|
| 1 | Alice | IT | 80000 | 2021-05-10 |
| 2 | Bob | HR | 60000 | 2022-08-15 |
| 3 | Charlie | IT | 90000 | 2019-12-01 |
Tasks:
โ๏ธ Find average salary by department
SELECT Department, AVG(Salary) AS AvgSalary
FROM Employees
GROUP BY Department;
โ๏ธ List employees who have been with the company for more than 3 years
SELECT Name, JoinDate
FROM Employees
WHERE JoinDate <= DATE_SUB(CURDATE(), INTERVAL 3 YEAR);
โ๏ธ Create a stored procedure to update salaries based on department
DELIMITER //
CREATE PROCEDURE UpdateSalaries()
BEGIN
UPDATE Employees SET Salary = Salary * 1.10 WHERE Department = 'IT';
END //
DELIMITER ;
๐ฏ Objective: Learn how to manage employee data using SQL.
---
๐3
๐น Final Challenge: Solve an Advanced SQL Problem
Problem Statement:
You have a table with user transactions. Find the second highest transaction amount for each user.
Dataset: Transactions Table
| TransactionID | UserID | Amount |
|--------------|--------|--------|
| 1 | 101 | 500 |
| 2 | 101 | 700 |
| 3 | 102 | 900 |
| 4 | 101 | 800 |
| 5 | 102 | 1000 |
Solution Using Window Function
โ๏ธ This finds the second highest transaction for each user using RANK().
---
๐น Next Steps: What to Do After Completing This Course?
๐ 1. Keep Practicing SQL
- Use LeetCode (SQL section) for solving challenges.
- Try HackerRank SQL challenges to strengthen your skills.
๐ 2. Build More Projects
- Create a Portfolio Website showcasing your SQL projects.
- Work on real-world datasets (Kaggle, Google BigQuery).
๐ 3. Learn Advanced Topics
- Data Warehousing (OLAP, Snowflake Schema)
- ETL (Extract, Transform, Load) Concepts
- NoSQL Databases (MongoDB, Firebase)
๐ฏ 4. Get Certified
- Microsoft SQL Server Certification
- Google Data Analytics Certificate
- IBM Data Science Professional Certificate
๐ผ 5. Apply for Jobs & Freelance Work
- Look for SQL-related job roles (Data Analyst, Data Engineer).
- Offer SQL consulting services on platforms like Upwork & Fiverr.
---
๐น Final Thoughts: Congratulations on Finishing 30 Days of SQL! ๐
๐ Youโve mastered SQL fundamentals & real-world applications!
โ๏ธ You can now write complex queries, optimize performance, and analyze data.
โ๏ธ Youโre ready to work with databases professionally!
๐ฌ Drop a comment if you completed this 30-day challenge!
๐ฅ Like & Share if this journey helped you!
๐ Next Stop: Data Science, Python, or MAchine LEarning? Whatโs your next goal? Let me know! ๐
Problem Statement:
You have a table with user transactions. Find the second highest transaction amount for each user.
Dataset: Transactions Table
| TransactionID | UserID | Amount |
|--------------|--------|--------|
| 1 | 101 | 500 |
| 2 | 101 | 700 |
| 3 | 102 | 900 |
| 4 | 101 | 800 |
| 5 | 102 | 1000 |
Solution Using Window Function
SELECT UserID, Amount
FROM (
SELECT UserID, Amount,
RANK() OVER (PARTITION BY UserID ORDER BY Amount DESC) AS rnk
FROM Transactions
) Ranked
WHERE rnk = 2;
โ๏ธ This finds the second highest transaction for each user using RANK().
---
๐น Next Steps: What to Do After Completing This Course?
๐ 1. Keep Practicing SQL
- Use LeetCode (SQL section) for solving challenges.
- Try HackerRank SQL challenges to strengthen your skills.
๐ 2. Build More Projects
- Create a Portfolio Website showcasing your SQL projects.
- Work on real-world datasets (Kaggle, Google BigQuery).
๐ 3. Learn Advanced Topics
- Data Warehousing (OLAP, Snowflake Schema)
- ETL (Extract, Transform, Load) Concepts
- NoSQL Databases (MongoDB, Firebase)
๐ฏ 4. Get Certified
- Microsoft SQL Server Certification
- Google Data Analytics Certificate
- IBM Data Science Professional Certificate
๐ผ 5. Apply for Jobs & Freelance Work
- Look for SQL-related job roles (Data Analyst, Data Engineer).
- Offer SQL consulting services on platforms like Upwork & Fiverr.
---
๐น Final Thoughts: Congratulations on Finishing 30 Days of SQL! ๐
๐ Youโve mastered SQL fundamentals & real-world applications!
โ๏ธ You can now write complex queries, optimize performance, and analyze data.
โ๏ธ Youโre ready to work with databases professionally!
๐ฌ Drop a comment if you completed this 30-day challenge!
๐ฅ Like & Share if this journey helped you!
๐ Next Stop: Data Science, Python, or MAchine LEarning? Whatโs your next goal? Let me know! ๐
๐5โค3
Hello everyone!!
I hope this 30 day sql series helped you all.
Looking forward to your feedback for future series!! ๐
I hope this 30 day sql series helped you all.
Looking forward to your feedback for future series!! ๐
โค19๐6โ1
SQL books wonโt teach you this.
Natural Keys vs. Autoincrement IDs vs. Public IDs. (or maybe all together)
๐ก๐ฎ๐๐๐ฟ๐ฎ๐น ๐๐ฒ๐๐
Natural keys carry intrinsic meaning because they are part of the domain.
They are directly related to the data, making them intuitive and easy to understand. Examples include email addresses or employee IDs.
The problem is that they are usually not good for performance, but they can also be a security risk if you expose them.
๐๐๐๐ผ๐ถ๐ป๐ฐ๐ฟ๐ฒ๐บ๐ฒ๐ป๐ ๐๐๐
Autoincrement IDs automatically generate unique integers to identify rows within a table.
They are often used as primary keys.
Simple integers are fast for the database to index and query. They provide optimal performance.
However, they are vulnerable to enumeration attacks since predicting the next or previous record is easy.
๐ฃ๐๐ฏ๐น๐ถ๐ฐ ๐๐๐ (๐จ๐จ๐๐๐)
UUIDs (Universally Unique Identifiers) are 128-bit identifiers used to uniquely identify information without relying on a centralized authority.
They are difficult to guess, making them suitable for public exposure in APIs.
The problem is they are larger and more complex than integers. This can impact performance, particularly in indexing and storage.
๐๐ถ๐ป๐ฑ๐ถ๐ป๐ด ๐๐ต๐ฒ ๐ฆ๐๐ฒ๐ฒ๐ ๐ฆ๐ฝ๐ผ๐: ๐ ๐ ๐ถ๐ ๐ฒ๐ฑ ๐๐ฝ๐ฝ๐ฟ๐ผ๐ฎ๐ฐ๐ต
Combining different types of keys can offer a balanced solution:
โข InternalID: Used for internal operations and relationships between tables.
โข PublicID: Used in API responses and endpoints to securely reference user records.
โข Email (Natural Key): Used to ensure unique identification of users within the business logic.
The mixed approach keeps your system fast, secure, and easy to understand.
Natural Keys vs. Autoincrement IDs vs. Public IDs. (or maybe all together)
๐ก๐ฎ๐๐๐ฟ๐ฎ๐น ๐๐ฒ๐๐
Natural keys carry intrinsic meaning because they are part of the domain.
They are directly related to the data, making them intuitive and easy to understand. Examples include email addresses or employee IDs.
The problem is that they are usually not good for performance, but they can also be a security risk if you expose them.
๐๐๐๐ผ๐ถ๐ป๐ฐ๐ฟ๐ฒ๐บ๐ฒ๐ป๐ ๐๐๐
Autoincrement IDs automatically generate unique integers to identify rows within a table.
They are often used as primary keys.
Simple integers are fast for the database to index and query. They provide optimal performance.
However, they are vulnerable to enumeration attacks since predicting the next or previous record is easy.
๐ฃ๐๐ฏ๐น๐ถ๐ฐ ๐๐๐ (๐จ๐จ๐๐๐)
UUIDs (Universally Unique Identifiers) are 128-bit identifiers used to uniquely identify information without relying on a centralized authority.
They are difficult to guess, making them suitable for public exposure in APIs.
The problem is they are larger and more complex than integers. This can impact performance, particularly in indexing and storage.
๐๐ถ๐ป๐ฑ๐ถ๐ป๐ด ๐๐ต๐ฒ ๐ฆ๐๐ฒ๐ฒ๐ ๐ฆ๐ฝ๐ผ๐: ๐ ๐ ๐ถ๐ ๐ฒ๐ฑ ๐๐ฝ๐ฝ๐ฟ๐ผ๐ฎ๐ฐ๐ต
Combining different types of keys can offer a balanced solution:
โข InternalID: Used for internal operations and relationships between tables.
โข PublicID: Used in API responses and endpoints to securely reference user records.
โข Email (Natural Key): Used to ensure unique identification of users within the business logic.
The mixed approach keeps your system fast, secure, and easy to understand.
โค6๐4
Are you done with watching ๐๐๐ tutorials but don't know where to practice it?
Check out these top 11 online sources that provide practical exercises and challenges to help you master SQL:
1. SQL Zoo: https://sqlzoo.net/wiki/SQL_Tutorial
2. SQLBolt : https://sqlbolt.com/
3. SQLPad: https://sqlpad.io/
4. Mode: https://mode.com/
5. Strata Scratch: https://www.stratascratch.com/
6. LeetCode: https://leetcode.com/problemset/all/
7. HackerRank: https://www.hackerrank.com/domains/sql
8. W3 Schools: https://www.w3schools.com/sql/default.asp
9. SQL Roadmap: https://t.me/sqlspecialist/386
10. Learnsql: https://learnsql.com/?ref=analyst
Check out these top 11 online sources that provide practical exercises and challenges to help you master SQL:
1. SQL Zoo: https://sqlzoo.net/wiki/SQL_Tutorial
2. SQLBolt : https://sqlbolt.com/
3. SQLPad: https://sqlpad.io/
4. Mode: https://mode.com/
5. Strata Scratch: https://www.stratascratch.com/
6. LeetCode: https://leetcode.com/problemset/all/
7. HackerRank: https://www.hackerrank.com/domains/sql
8. W3 Schools: https://www.w3schools.com/sql/default.asp
9. SQL Roadmap: https://t.me/sqlspecialist/386
10. Learnsql: https://learnsql.com/?ref=analyst
Sqlbolt
SQLBolt - Learn SQL - Introduction to SQL
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
โค9๐3
What does TCL stand for in SQL?
Anonymous Quiz
11%
A) Table Control Language
79%
B) Transaction Control Language
6%
C) Temporary Command Language
3%
D) Trigger Control Language
Which SQL statement is used to insert new data in a database?
Anonymous Quiz
27%
Insert New
3%
Add Record
6%
Add New
64%
Insert Into
๐3
Which of the following statements about TCL (Transaction Control Language) in SQL is FALSE?
Anonymous Quiz
23%
A) TCL commands are used to manage transactions in a database
39%
B) COMMIT and ROLLBACK are examples of TCL commands.
26%
C) TCL ensures automatic rollback of every transaction after execution.
12%
D) SAVEPOINT allows partial rollback within a transaction.
๐2
This media is not supported in your browser
VIEW IN TELEGRAM
Hurry up and enroll within Navratri offer and get low prices! ๐ซถ๐ป๐
WhatsApp at +91-9910986344
WhatsApp at +91-9910986344
๐2
Which of the following matches the definition given below: It is an artificial key that aims to uniquely identify each record.
Anonymous Quiz
61%
Primary Key
19%
Foreign Key
13%
Surrogate Key
8%
composite Key
Hey everyone!
It's my dad's birthday today! ๐๐
To celebrate, I'm offering a huge discount on my live python courseโnow just โน3000!
But hurry, this offer is only valid for the next 24 hours! โณ
Grab your spot now! ๐
Ping me on WhatsApp at +91-9910986344
Before the offer ends ๐๐ฅณ
It's my dad's birthday today! ๐๐
To celebrate, I'm offering a huge discount on my live python courseโnow just โน3000!
But hurry, this offer is only valid for the next 24 hours! โณ
Grab your spot now! ๐
Ping me on WhatsApp at +91-9910986344
Before the offer ends ๐๐ฅณ
๐5๐2
The most popular programming languages:
1. Python
2. TypeScript
3. JavaScript
4. C#
5. HTML
6. Rust
7. C++
8. C
9. Go
10. Lua
11. Kotlin
12. Java
13. Swift
14. Jupyter Notebook
15. Shell
16. CSS
17. GDScript
18. Solidity
19. Vue
20. PHP
21. Dart
22. Ruby
23. Objective-C
24. PowerShell
25. Scala
According to the Latest GitHub Repositories
1. Python
2. TypeScript
3. JavaScript
4. C#
5. HTML
6. Rust
7. C++
8. C
9. Go
10. Lua
11. Kotlin
12. Java
13. Swift
14. Jupyter Notebook
15. Shell
16. CSS
17. GDScript
18. Solidity
19. Vue
20. PHP
21. Dart
22. Ruby
23. Objective-C
24. PowerShell
25. Scala
According to the Latest GitHub Repositories
๐3โค1
SQL, or Structured Query Language, is a domain-specific language used to manage and manipulate relational databases.
A - Aggregate Functions: Functions like COUNT, SUM, AVG, MIN, and MAX used to perform operations on data in a database.
B - BETWEEN: A SQL operator used to filter results within a specific range.
C - CREATE TABLE: SQL statement for creating a new table in a database.
D - DELETE: SQL statement used to delete records from a table.
E - EXISTS: SQL operator used in a subquery to test if a specified condition exists.
F - FOREIGN KEY: A field in a database table that is a primary key in another table, establishing a link between the two tables.
G - GROUP BY: SQL clause used to group rows that have the same values in specified columns.
H - HAVING: SQL clause used in combination with GROUP BY to filter the results.
I - INNER JOIN: SQL clause used to combine rows from two or more tables based on a related column between them.
J - JOIN: Combines rows from two or more tables based on a related column.
K - KEY: A field or set of fields in a database table that uniquely identifies each record.
L - LIKE: SQL operator used in a WHERE clause to search for a specified pattern in a column.
M - MODIFY: SQL command used to modify an existing database table.
N - NULL: Represents missing or undefined data in a database.
O - ORDER BY: SQL clause used to sort the result set in ascending or descending order.
P - PRIMARY KEY: A field in a table that uniquely identifies each record in that table.
Q - QUERY: A request for data from a database using SQL.
R - ROLLBACK: SQL command used to undo transactions that have not been saved to the database.
S - SELECT: SQL statement used to query the database and retrieve data.
T - TRUNCATE: SQL command used to delete all records from a table without logging individual row deletions.
U - UPDATE: SQL statement used to modify the existing records in a table.
V - VIEW: A virtual table based on the result of a SELECT query.
W - WHERE: SQL clause used to filter the results of a query based on a specified condition.
X - (E)XISTS: Used in conjunction with SELECT to test the existence of rows returned by a subquery.
Z - ZERO: Represents the absence of a value in numeric fields or the initial state of boolean fields.
Here you can find essential Pyspark Resources๐
https://www.instagram.com/codingdidi
Like this post if you need more ๐โค๏ธ
Hope it helps :)
A - Aggregate Functions: Functions like COUNT, SUM, AVG, MIN, and MAX used to perform operations on data in a database.
B - BETWEEN: A SQL operator used to filter results within a specific range.
C - CREATE TABLE: SQL statement for creating a new table in a database.
D - DELETE: SQL statement used to delete records from a table.
E - EXISTS: SQL operator used in a subquery to test if a specified condition exists.
F - FOREIGN KEY: A field in a database table that is a primary key in another table, establishing a link between the two tables.
G - GROUP BY: SQL clause used to group rows that have the same values in specified columns.
H - HAVING: SQL clause used in combination with GROUP BY to filter the results.
I - INNER JOIN: SQL clause used to combine rows from two or more tables based on a related column between them.
J - JOIN: Combines rows from two or more tables based on a related column.
K - KEY: A field or set of fields in a database table that uniquely identifies each record.
L - LIKE: SQL operator used in a WHERE clause to search for a specified pattern in a column.
M - MODIFY: SQL command used to modify an existing database table.
N - NULL: Represents missing or undefined data in a database.
O - ORDER BY: SQL clause used to sort the result set in ascending or descending order.
P - PRIMARY KEY: A field in a table that uniquely identifies each record in that table.
Q - QUERY: A request for data from a database using SQL.
R - ROLLBACK: SQL command used to undo transactions that have not been saved to the database.
S - SELECT: SQL statement used to query the database and retrieve data.
T - TRUNCATE: SQL command used to delete all records from a table without logging individual row deletions.
U - UPDATE: SQL statement used to modify the existing records in a table.
V - VIEW: A virtual table based on the result of a SELECT query.
W - WHERE: SQL clause used to filter the results of a query based on a specified condition.
X - (E)XISTS: Used in conjunction with SELECT to test the existence of rows returned by a subquery.
Z - ZERO: Represents the absence of a value in numeric fields or the initial state of boolean fields.
Here you can find essential Pyspark Resources๐
https://www.instagram.com/codingdidi
Like this post if you need more ๐โค๏ธ
Hope it helps :)
๐7โค1