Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ica-13-Dms Lab7

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Enter password: ************

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 4
Server version: 5.6.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> Create database clg;


Query OK, 1 row affected (0.01 sec)

mysql> Use clg;


Database changed
mysql> Create table faculty
-> (id int(5),
-> name varchar(20),
-> dept varchar(20),
-> experience varchar(5));
Query OK, 0 rows affected (0.24 sec)

mysql> Insert INTO faculty


-> Values(1,"aa","IT","3.5");
Query OK, 1 row affected (0.08 sec)

mysql> Insert INTO faculty


-> Values(2,"ccc","Computer","9");
Query OK, 1 row affected (0.08 sec)

mysql> Insert INTO faculty


-> Values(3,"ddd","Computer","2.9");
Query OK, 1 row affected (0.08 sec)

mysql> Insert INTO faculty


-> Values(4,"ggg","Mechanical","4");
Query OK, 1 row affected (0.08 sec)

mysql> Insert INTO faculty


-> Values(5,"zzz","IT","6");
Query OK, 1 row affected (0.07 sec)

mysql> Insert INTO faculty


-> Values(6,"bob","ENTC","4");
Query OK, 1 row affected (0.07 sec)

mysql> Select * from faculty;


+------+------+------------+------------+
| id | name | dept | experience |
+------+------+------------+------------+
| 1 | aa | IT | 3.5 |
| 2 | ccc | Computer | 9 |
| 3 | ddd | Computer | 2.9 |
| 4 | ggg | Mechanical | 4 |
| 5 | zzz | IT | 6 |
| 6 | bob | ENTC | 4 |
+------+------+------------+------------+
6 rows in set (0.06 sec)

mysql> Create table faculty_backup


-> (action varchar(100),
-> old_id int(11),
-> new_id int(11),
-> date int(5));
Query OK, 0 rows affected (0.29 sec)

mysql> desc faculty_backup;


+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| action | varchar(100) | YES | | NULL | |
| old_id | int(11) | YES | | NULL | |
| new_id | int(11) | YES | | NULL | |
| date | int(5) | YES | | NULL | |
+--------+--------------+------+-----+---------+-------+
4 rows in set (0.08 sec)

mysql> Create table faculty_backup1


-> (action varchar(100),
-> old_id int(11),
-> new_id int(11),
-> date date);
Query OK, 0 rows affected (0.29 sec)

mysql> delimiter $$
mysql> drop trigger if exists facultydata1 $$
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> Create trigger facultydata1


-> before insert on faculty for each row
-> begin
-> insert into faculty_backup1 set action='insert',new_id=new.id,date=now();
-> end $$
Query OK, 0 rows affected (0.13 sec)

mysql> delimiter ;
mysql> Insert INTO faculty
-> Values(7,"bob","ENTC",4);
Query OK, 1 row affected (0.10 sec)

mysql> Select * from faculty_backup1;


+--------+--------+--------+------------+
| action | old_id | new_id | date |
+--------+--------+--------+------------+
| insert | NULL | 7 | 2022-11-22 |
+--------+--------+--------+------------+
1 row in set (0.00 sec)

mysql> Insert INTO faculty


-> Values(8,"rob","IT",5);
Query OK, 1 row affected (0.07 sec)

mysql> Select * from faculty_backup1;


+--------+--------+--------+------------+
| action | old_id | new_id | date |
+--------+--------+--------+------------+
| insert | NULL | 7 | 2022-11-22 |
| insert | NULL | 8 | 2022-11-22 |
+--------+--------+--------+------------+
2 rows in set (0.00 sec)

mysql> delimiter $$
mysql> drop trigger if exists facultydata2 $$
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create trigger facultydata2


-> before delete on faculty for each row
-> begin
-> insert into faculty_backup1 set action='delete',old_id=old.id,date=now();
-> end $$
Query OK, 0 rows affected (0.07 sec)

mysql> delimiter ;
mysql> Select * from faculty;
+------+------+------------+------------+
| id | name | dept | experience |
+------+------+------------+------------+
| 1 | aa | IT | 3.5 |
| 2 | ccc | Computer | 9 |
| 3 | ddd | Computer | 2.9 |
| 4 | ggg | Mechanical | 4 |
| 5 | zzz | IT | 6 |
| 6 | bob | ENTC | 4 |
| 7 | bob | ENTC | 4 |
| 8 | rob | IT | 5 |
+------+------+------------+------------+
8 rows in set (0.00 sec)

mysql> delete from faculty where id=7;


Query OK, 1 row affected (0.09 sec)

mysql> Select * from faculty_backup1;


+--------+--------+--------+------------+
| action | old_id | new_id | date |
+--------+--------+--------+------------+
| insert | NULL | 7 | 2022-11-22 |
| insert | NULL | 8 | 2022-11-22 |
| delete | 7 | NULL | 2022-11-22 |
+--------+--------+--------+------------+
3 rows in set (0.00 sec)

mysql>

You might also like