Advanced Mixed Data in SQL
In the last we have complied all the imprtant queries under the one advanced SQL cheat sheet.
67. Stored Procedures: Precompiled SQL Statements That Can Be Executed with a Single Command
CREATE PROCEDURE get_employee_count()
BEGIN
SELECT COUNT(*) FROM employees;
END;
This query creates a stored procedure named get_employee_count that returns the count of employees.
68. Triggers: Automatically Execute a Set of SQL Statements When a Specified Event Occurs
CREATE TRIGGER before_employee_insert
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
SET NEW.creation_date = NOW();
END;
This query creates a trigger named before_employee_insert that sets the creation_date column to the current date and time before inserting a new employee record.
69. User-defined Functions (UDFs): Custom SQL Functions Created by Users to Perform Specific Tasks
CREATE FUNCTION calculate_bonus(salary DECIMAL) RETURNS DECIMAL
BEGIN
RETURN salary * 0.1; -- 10% bonus
END;
This query creates a user-defined function named calculate_bonus that calculates the bonus based on the salary.
70. Common Table Expressions (CTEs): Temporary Result Sets That Can Be Referenced Within a SELECT, INSERT, UPDATE, or DELETE Statement
WITH high_paid_employees AS (
SELECT * FROM employees WHERE salary > 60000
)
SELECT * FROM high_paid_employees;
This query uses a common table expression named high_paid_employees to retrieve all employees with a salary greater than 60000.
SQL Cheat Sheet
In this article, we will explore the ultimate SQL cheat sheet with the PDF, covering a wide range of SQL commands, Joins in SQL, CRUD Operations, SQL Trigger, SQL Transactions, and advanced topics to help master SQL effectively.
SQL (Structured Query Language) is a Query language used for managing and manipulating relational databases databases. It allows users to interact with databases. SQL allows users to perform various tasks such as querying data, updating data, inserting new records, deleting records, creating and modifying database schemas, and managing permissions.
Table of Content
- Create a Database in SQL
- Creating Data in SQL
- Reading/Querying Data in SQL
- Updating/Manipulating Data in SQL
- Deleting Data in SQL
- Filtering Data in SQL
- SQL Operator
- Aggregation Data in SQL
- Constraints in SQL
- Joins in SQL
- SQL Functions
- Subqueries in SQL
- Views in SQL
- Indexes in SQL
- Transactions in SQL
- Advanced Mixed Data in SQL
- SQL Cheat Sheet PDF
Contact Us