0% found this document useful (0 votes)
2 views

Assignment 9

The document outlines the creation of two tables, Employee and new_rec, in a MySQL database. It includes the insertion of employee records and the implementation of a trigger that logs the insertion date of new employees into the new_rec table. After inserting a new employee, the trigger successfully records the insertion date in the new_rec table.

Uploaded by

Mrinmoy Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 9

The document outlines the creation of two tables, Employee and new_rec, in a MySQL database. It includes the insertion of employee records and the implementation of a trigger that logs the insertion date of new employees into the new_rec table. After inserting a new employee, the trigger successfully records the insertion date in the new_rec table.

Uploaded by

Mrinmoy Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> use assignment_9;

Database changed

mysql> CREATE TABLE Employee (


-> emp_id INT PRIMARY KEY,
-> salary DECIMAL(10, 2)
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE new_rec (


-> emp_id INT,
-> insertion_date DATETIME
-> );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO Employee (emp_id, salary) VALUES


-> (1, 50000.00),
-> (2, 60000.00),
-> (3, 75000.00);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from Employee;


+--------+----------+
| emp_id | salary |
+--------+----------+
| 1 | 50000.00 |
| 2 | 60000.00 |
| 3 | 75000.00 |
+--------+----------+
4 rows in set (0.00 sec)

mysql> DELIMITER $$
mysql> CREATE TRIGGER new_rec_before_insert
-> BEFORE INSERT ON Employee
-> FOR EACH ROW
-> BEGIN
-> INSERT INTO new_rec (emp_id, insertion_date)
-> VALUES (NEW.emp_id, NOW());
-> END;
-> $$
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;

mysql> INSERT INTO Employee (emp_id, salary) VALUES (4, 80000.00);


Query OK, 1 row affected (0.00 sec)
mysql> select * from Employee;
+--------+----------+
| emp_id | salary |
+--------+----------+
| 1 | 50000.00 |
| 2 | 60000.00 |
| 3 | 75000.00 |
| 4 | 80000.00 |
+--------+----------+
4 rows in set (0.00 sec)

mysql> select * from new_rec;


+--------+---------------------+
| emp_id | insertion_date |
+--------+---------------------+
| 4 | 2023-11-04 20:29:14 |
+--------+---------------------+
1 row in set (0.00 sec)

You might also like