RDBMS Lab File
RDBMS Lab File
Contents
Create New Database..................................................................................................................................3
Select Database to use................................................................................................................................3
Create a Table and Display all Tables in Database........................................................................................4
Insert record into Table................................................................................................................................5
Display All Records in Table.........................................................................................................................6
Modify Table Attributes...............................................................................................................................6
Add a Constraint..........................................................................................................................................6
Drop Constraint...........................................................................................................................................7
Setting Up Foreign Key Constraint...............................................................................................................7
Display Selected Attributes from Table........................................................................................................7
Display Records in Order.............................................................................................................................8
Creating Alias...............................................................................................................................................9
Rename a column......................................................................................................................................10
Change Dimensions or Column Size...........................................................................................................10
Update Entire Column in a Table...............................................................................................................10
Rename a Table.........................................................................................................................................11
Update a Record........................................................................................................................................11
Delete a Record from Table.......................................................................................................................11
Delete a Table............................................................................................................................................12
GROUPBY Clause........................................................................................................................................12
HAVING Clause..........................................................................................................................................12
Using Wildcards.........................................................................................................................................13
BETWEEN Clause.......................................................................................................................................13
IN Clause....................................................................................................................................................14
Create a View.............................................................................................................................................14
Left Join.....................................................................................................................................................15
Right Join...................................................................................................................................................15
Full Join......................................................................................................................................................16
Self-Join.....................................................................................................................................................17
EXPLAIN Command....................................................................................................................................17
Create and Show Index..............................................................................................................................17
1|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Drop Index.................................................................................................................................................18
Create a Trigger.........................................................................................................................................18
Show Triggers............................................................................................................................................20
2|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
2. use invoicemgsys_clone;
3|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
4. show tables;
4|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
5|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Add a Constraint
6|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Drop Constraint
8|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Creating Alias
9|Page
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Rename a column
Rename a Table
10 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Update a Record
5. update customers set town= 'Jaipur' where name= 'Brudo' && id= 96;
select * from customers where id= 96;
Delete a Table
11 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
GROUPBY Clause
HAVING Clause
Using Wildcards
12 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
BETWEEN Clause
13 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
IN Clause
Create a View
14 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Left Join
Right Join
3. -- to display all details of customer along with billing status details, pending
payment > 400
select bill.status, bill.total, customers.name from customers
right join bill
on customers.id= bill.id
where bill.status='open' and bill.total> 400;
15 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Full Join
Self-Join
16 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
EXPLAIN Command
Drop Index
17 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
Create a Trigger
4. -- before delete
delimiter $$
CREATE TRIGGER Backup1 BEFORE DELETE ON employee
FOR EACH ROW
BEGIN
INSERT INTO employee_backup
VALUES (OLD.employee_no, OLD.employee_name,
OLD.job, OLD.salary);
END;
5. -- Before insert
delimiter $$
18 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
6. -- before update
DELIMITER $$
CREATE TRIGGER before_update_trigger
BEFORE UPDATE ON employee
FOR EACH ROW
BEGIN
IF NEW.salary < OLD.salary THEN
SET NEW.salary = OLD.salary;
END IF;
END$$
19 | P a g e
| Om Utsav [IOT And Intelligent System - 2021]
RDBMS LAB FILE
DELIMITER ;
Show Triggers
7. show triggers;
20 | P a g e