File: /home/lab04/Desktop/Aniruddha/trigger Page 1 of 3
mysql -u root
[sudo] password for lab04:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.41-0ubuntu0.22.04.1 (Ubuntu)
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
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> show databases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'sho' at line 2
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| AD |
| EMart |
| Hos |
| Hospital |
| OLAP |
| djj |
| funtion |
| huu |
| information_schema |
| mayank |
| mysql |
| olap |
| olaps |
| performance_schema |
| sales |
| sayali |
| shreya |
| shreyanka |
| shreyanka1 |
| student |
| student12 |
| sys |
+--------------------+
22 rows in set (0.00 sec)
mysql> use student;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables
-> ;
+-------------------+
| Tables_in_student |
+-------------------+
| Customer |
| Emp |
| Employee |
| Employee1 |
| Employees |
| Std2 |
| Stu1 |
| Stu2 |
| students |
File: /home/lab04/Desktop/Aniruddha/trigger Page 2 of 3
+-------------------+
9 rows in set (0.00 sec)
mysql> select* from Emp;
+--------+---------+----------+--------+
| emp_id | emp_sal | emp_dept | emp_na |
+--------+---------+----------+--------+
| 1 | 10000 | comp | ajay |
| 2 | 20000 | comp | ram |
| 3 | 30000 | cse | rocky |
| 4 | 40000 | cse | mickey |
| 5 | 50000 | Aids | tom |
+--------+---------+----------+--------+
5 rows in set (0.00 sec)
mysql> create trigger new_tri before insert on Emp for each row set
new.emp_sal=new.emp_sal+10000;
Query OK, 0 rows affected (0.11 sec)
mysql> insert into Emp values(6,50000,'Aids','Jack')
-> ;
Query OK, 1 row affected (0.09 sec)
mysql> select* from Emp;
+--------+---------+----------+--------+
| emp_id | emp_sal | emp_dept | emp_na |
+--------+---------+----------+--------+
| 1 | 10000 | comp | ajay |
| 2 | 20000 | comp | ram |
| 3 | 30000 | cse | rocky |
| 4 | 40000 | cse | mickey |
| 5 | 50000 | Aids | tom |
| 6 | 60000 | Aids | Jack |
+--------+---------+----------+--------+
6 rows in set (0.00 sec)
mysql> insert into Emp values(7,60000,'comp','Sandy');
Query OK, 1 row affected (0.10 sec)
mysql> select* from Emp;
+--------+---------+----------+--------+
| emp_id | emp_sal | emp_dept | emp_na |
+--------+---------+----------+--------+
| 1 | 10000 | comp | ajay |
| 2 | 20000 | comp | ram |
| 3 | 30000 | cse | rocky |
| 4 | 40000 | cse | mickey |
| 5 | 50000 | Aids | tom |
| 6 | 60000 | Aids | Jack |
| 7 | 70000 | comp | Sandy |
+--------+---------+----------+--------+
7 rows in set (0.00 sec)
mysql> create table Emp10(emp_sal int);
Query OK, 0 rows affected (1.25 sec)
mysql> create trigger new_tri1 after insert on Emp for each row insert into Emp10
values(new.emp_sal);
Query OK, 0 rows affected (0.18 sec)
mysql> insert into Emp values(8,600,'comp','Sandy');
Query OK, 1 row affected (0.11 sec)
mysql> select* from Emp;
+--------+---------+----------+--------+
| emp_id | emp_sal | emp_dept | emp_na |
File: /home/lab04/Desktop/Aniruddha/trigger Page 3 of 3
+--------+---------+----------+--------+
| 1 | 10000 | comp | ajay |
| 2 | 20000 | comp | ram |
| 3 | 30000 | cse | rocky |
| 4 | 40000 | cse | mickey |
| 5 | 50000 | Aids | tom |
| 6 | 60000 | Aids | Jack |
| 7 | 70000 | comp | Sandy |
| 8 | 10600 | comp | Sandy |
+--------+---------+----------+--------+
8 rows in set (0.00 sec)
mysql> select* from Emp10;
+---------+
| emp_sal |
+---------+
| 10600 |
+---------+
1 row in set (0.00 sec)
mysql> create view view1 as select * from Emp;
Query OK, 0 rows affected (0.15 sec)
mysql> select* from view1;
+--------+---------+----------+--------+
| emp_id | emp_sal | emp_dept | emp_na |
+--------+---------+----------+--------+
| 1 | 10000 | comp | ajay |
| 2 | 20000 | comp | ram |
| 3 | 30000 | cse | rocky |
| 4 | 40000 | cse | mickey |
| 5 | 50000 | Aids | tom |
| 6 | 60000 | Aids | Jack |
| 7 | 70000 | comp | Sandy |
| 8 | 10600 | comp | Sandy |
+--------+---------+----------+--------+
8 rows in set (0.01 sec)
mysql> create view view2 as select * from Emp where emp_sal>50000;
Query OK, 0 rows affected (0.15 sec)
mysql> select* from view2;
+--------+---------+----------+--------+
| emp_id | emp_sal | emp_dept | emp_na |
+--------+---------+----------+--------+
| 6 | 60000 | Aids | Jack |
| 7 | 70000 | comp | Sandy |
+--------+---------+----------+--------+
2 rows in set (0.00 sec)