0% found this document useful (0 votes)
6 views12 pages

Dbms

The document outlines SQL commands for creating tables, inserting data, and verifying table creation, including the use of COMMIT and ROLLBACK. It details various SQL functions such as COUNT, SUM, AVG, and operations like UNION, INTERSECT, and EXCEPT. Additionally, it explains the concept of triggers in SQL, providing syntax and a scenario for logging employee insertions into a log table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

Dbms

The document outlines SQL commands for creating tables, inserting data, and verifying table creation, including the use of COMMIT and ROLLBACK. It details various SQL functions such as COUNT, SUM, AVG, and operations like UNION, INTERSECT, and EXCEPT. Additionally, it explains the concept of triggers in SQL, providing syntax and a scenario for logging employee insertions into a log table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

Create Table Command

2. Insert Data into Table

3. Verify Table Creation


To check if the table was created and populated correctly:
1. COMMIT and ROLLBACK

• Description: COMMIT saves all changes made to the database, while ROLLBACK undoes
changes since the last COMMIT.

a. Commit

b. Rollback
2. COUNT

• Description: COUNT returns the number of rows matching a condition.

3. SUM

• Description: Calculates the total sum of a numeric column.

4. AVG

• Description: Calculates the average of a numeric column.

5. LIMIT

• Description: Limits the number of rows returned by a query.


6. DISTINCT

• Description: Removes duplicate values from the result set.

7. UNION

• Description: Combines the results of two queries.

8. INTERSECT

• Description: Returns common rows between two queries.

Example:

SELECT name FROM employees WHERE department = 'IT'

INTERSECT

SELECT name FROM employees WHERE salary > 50000;


9. EXCEPT

• Description: Returns rows from the first query that are not in the second query.

Example:

SELECT name FROM employees

EXCEPT

SELECT name FROM employees WHERE department = 'HR';

10. PROJECTION

• Description: Selects specific columns.

11. SELECTION

• Description: Filters rows based on a condition.


12. LIKE

• Description: Filters rows using patterns.


13. IN

• Description: Filters rows based on a list of values.

14. MIN and MAX

• Description: Returns the smallest or largest value in a column.

15. AS

• Description: Renames a column or table.


16. BETWEEN

• Description: Filters rows within a range.

17. IS NULL and NOT NULL

• Description: Filters rows with NULL or non-NULL values.


18. OR

• Description: Combines multiple conditions.


19. TRIGGER

A trigger in SQL is a database object that automatically executes a predefined action in response to
certain events (such as INSERT, UPDATE, or DELETE) on a table. Triggers are useful for enforcing
business rules, maintaining audit trails, or validating data.

Creating a Trigger in MySQL


Syntax for Creating a Trigger :

CREATE TRIGGER trigger_name

AFTER | BEFORE INSERT | UPDATE | DELETE

ON table_name

FOR EACH ROW

BEGIN

-- SQL statements to execute

END;

Trigger Scenario

We want to record new employee insertions into a log table called employee_log, which contains the
following details:

• log_id (unique identifier)

• employee_id

• name

• action

• log_time

Step 1: Create the Log Table


Step 2: Create the Trigger

Step 3: Test the Trigger

1. Insert a New Employee into the employees Table:

2. Check the employee_log Table:

You might also like