0% found this document useful (0 votes)
18 views2 pages

DBMS8

Uploaded by

Manthan Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

DBMS8

Uploaded by

Manthan Mane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

it@it-OptiPlex-Tower-7010:~$ sudo mysql -u root -p

[sudo] password for it:


Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.36-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2024, 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> create database d8;


Query OK, 1 row affected (0.01 sec)

mysql> use d8;


Database changed

mysql> create table Library(Book_id int(10), Title varchar(20), Edition varchar(20), no_of_copies int (10));

mysql> create table Libraryaudit(Book_id int(10), Title varchar(20), Edition varchar(20), no_of_copies int(10), date_of_mod date,
Operation_type varchar(20), user varchar(20));

mysql> create table Transaction(Transaction_id int(20), Book_id int(10), Status varchar(20), no_of_copies int(10));

mysql> INSERT INTO Library (Book_id, Title, Edition, no_of_copies) VALUES

-> (1, 'Book One', 'First', 5),


-> (2, 'Book Two', 'Second', 3),
-> (3, 'Book Three', 'Third', 8),
-> (4, 'Book Four', 'Fourth', 2),
-> (5, 'Book Five', 'Fifth', 6),
-> (6, 'Book Six', 'First', 4),
-> (7, 'Book Seven', 'Second', 7),
-> (8, 'Book Eight', 'Third', 1),
-> (9, 'Book Nine', 'Fourth', 9),
-> (10, 'Book Ten', 'Fifth', 2);

mysql> INSERT INTO Libraryaudit (Book_id, Title, Edition, no_of_copies, date_of_mod, Operation_type, user) VALUES
-> (1, 'Book One', 'First', 5, '2024-10-01', 'INSERT', 'admin'),
-> (2, 'Book Two', 'Second', 3, '2024-10-02', 'INSERT', 'admin'),
-> (3, 'Book Three', 'Third', 8, '2024-10-03', 'UPDATE', 'librarian'),
-> (4, 'Book Four', 'Fourth', 2, '2024-10-04', 'DELETE', 'admin'),
-> (5, 'Book Five', 'Fifth', 6, '2024-10-05', 'INSERT', 'librarian'),
-> (6, 'Book Six', 'First', 4, '2024-10-06', 'UPDATE', 'admin'),
-> (7, 'Book Seven', 'Second', 7, '2024-10-07', 'INSERT', 'librarian'),
-> (8, 'Book Eight', 'Third', 1, '2024-10-08', 'DELETE', 'admin'),
-> (9, 'Book Nine', 'Fourth', 9, '2024-10-09', 'UPDATE', 'librarian'),
-> (10, 'Book Ten', 'Fifth', 2, '2024-10-10', 'INSERT', 'admin');

mysql> select * from Library;


+---------+------------+---------+--------------+
| Book_id | Title | Edition | no_of_copies |
+---------+------------+---------+--------------+
| 1 | Book One | First | 5 |
| 2 | Book Two | Second | 3 |
| 3 | Book Three | Third | 8 |
| 4 | Book Four | Fourth | 2 |
| 5 | Book Five | Fifth | 6 |
| 6 | Book Six | First | 4 |
| 7 | Book Seven | Second | 7 |
| 8 | Book Eight | Third | 1 |
| 9 | Book Nine | Fourth | 9 |
| 10 | Book Ten | Fifth | 2 |
+---------+------------+---------+--------------+
10 rows in set (0.00 sec)

mysql> select * from Libraryaudit;


+---------+------------+---------+--------------+-------------+----------------+-----------+
| Book_id | Title | Edition | no_of_copies | date_of_mod | operation_type | user |
+---------+------------+---------+--------------+-------------+----------------+-----------+
| 1 | Book One | First | 5 | 2024-10-01 | INSERT | admin |
| 2 | Book Two | Second | 3 | 2024-10-02 | INSERT | admin |
| 3 | Book Three | Third | 8 | 2024-10-03 | UPDATE | librarian |
| 4 | Book Four | Fourth | 2 | 2024-10-04 | DELETE | admin |
| 5 | Book Five | Fifth | 6 | 2024-10-05 | INSERT | librarian |
| 6 | Book Six | First | 4 | 2024-10-06 | UPDATE | admin |
| 7 | Book Seven | Second | 7 | 2024-10-07 | INSERT | librarian |
| 8 | Book Eight | Third | 1 | 2024-10-08 | DELETE | admin |
| 9 | Book Nine | Fourth | 9 | 2024-10-09 | UPDATE | librarian |
| 10 | Book Ten | Fifth | 2 | 2024-10-10 | INSERT | admin |
+---------+------------+---------+--------------+-------------+----------------+-----------+
10 rows in set (0.00 sec)

mysql> select * from Transaction;


Empty set (0.00 sec)
mysql> DELIMITER //
mysql>
mysql> CREATE TRIGGER after_library_update
-> AFTER UPDATE ON Library
-> FOR EACH ROW
-> BEGIN
-> INSERT INTO Libraryaudit (Book_id, Title, Edition, no_of_copies, date_of_mod, Operation_type, user)
-> VALUES (NEW.Book_id, NEW.Title, NEW.Edition, NEW.no_of_copies, CURDATE(), 'UPDATE', 'admin');
-> END;
->
-> //
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> DELIMITER ;
mysql> -- Insert a sample record
mysql> INSERT INTO Library (Book_id, Title, Edition, no_of_copies) VALUES
-> (1, 'Book One', 'First', 5);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> -- Update the record
mysql> UPDATE Library SET no_of_copies = 10 WHERE Book_id = 1;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> SELECT * FROM Libraryaudit;


+---------+------------+---------+--------------+-------------+----------------+-----------+
| Book_id | Title | Edition | no_of_copies | date_of_mod | operation_type | user |
+---------+------------+---------+--------------+-------------+----------------+-----------+
| 1 | Book One | First | 5 | 2024-10-01 | INSERT | admin |
| 2 | Book Two | Second | 3 | 2024-10-02 | INSERT | admin |
| 3 | Book Three | Third | 8 | 2024-10-03 | UPDATE | librarian |
| 4 | Book Four | Fourth | 2 | 2024-10-04 | DELETE | admin |
| 5 | Book Five | Fifth | 6 | 2024-10-05 | INSERT | librarian |
| 6 | Book Six | First | 4 | 2024-10-06 | UPDATE | admin |
| 7 | Book Seven | Second | 7 | 2024-10-07 | INSERT | librarian |
| 8 | Book Eight | Third | 1 | 2024-10-08 | DELETE | admin |
| 9 | Book Nine | Fourth | 9 | 2024-10-09 | UPDATE | librarian |
| 10 | Book Ten | Fifth | 2 | 2024-10-10 | INSERT | admin |
| 1 | Book One | First | 10 | 2024-10-08 | UPDATE | admin |
| 1 | Book One | First | 10 | 2024-10-08 | UPDATE | admin |
+---------+------------+---------+--------------+-------------+----------------+-----------+
12 rows in set (0.00 sec)

mysql>

You might also like