Lab Manual Content
Lab Manual Content
PROGRAM NO -1
OBJECTIVE:
Draw E-R diagram and convert entities and relationships to relation table for a given scenario.
Two assignments shall be carried out i.e. consider two different scenarios (eg. bank, college)
1. COLLEGE DATABSE
STUDENT(USN,SName,Address,Phone,Gender)
SEMSEC(SSID,Sem,Sec)
CLASS(USN,SSID)
SUBJECT(Subcode,Title,Sem,CREDITS)
IAMARKS (USN,Subcode,SSID,Test1,Test2,Test3,FinallA)
PROCEDURE:
1. Create: Open EDRAW software , draw the diagram after that save the diagram .
OUT PUT
DLOCATION(DNo, DLoc)
DNo)WORKS_ON(SSN,PNo, Hours)
PROGRAM NO -2
OBJECTIVE:
Viewing all databases, creating a database, viewing all tables in a Database, creating tables (With
and Without constraints), Inserting/Updating/Deleting Records in a Table, Saving (Commit) and
Undoing(rollback)
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
Consider the Inventory Database with the following
Product(PID:number;Name:Text;Price:Number)
Purchase(PO:Number;PID:Number;Qty:Number)
Steps:
inventory001;mysql> use
inventory001;
Step 2: Create tables Product and Purchase with and without constraint
mysql> create table product (pidint(10) primary key, name varchar(15) not null, price int(8));
mysql>desc product;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| pid | int | NO | PRI | NULL | |
| name | varchar(15) | NO | | NULL | |
| price | int | YES | | NULL | |
+ + + + + + -+3 rows in set (0.07 sec)
mysql> create table purchase (po int(10) primary key,prod_id int(10) references product(pid),
mysql>desc
purchase;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| po | int | NO | PRI | NULL | |
+ +
| Tables_in_inventory001 |
+ +
| product |
| purchase |
+ +
Step 4: Insert five tuples into each relation
+ + + +
| po |prod_id | qty |
+ + + +
| 101 | 10 | 25 |
| 102 | 40 | 20 |
| 104 | 40 | 50 |
| 105 | 40 | 10 |
| 107 | 30 | 40 |
+ + + + 5 rows in set (0.00 sec)
Step 6: Update the product name for the PID = 40 as CAMERA
+ + + +
| pid | name | price |
+ + + +
| 10 | printer | 20000 |
| 20 | keyboard | 20000 |
| 30 | monitor | 15000 |
| 40 | camera | 25000 |
| 50 | scanner | 14000 |
+ + + +5 rows in set (0.00 sec)
+ + + +
| pid | name | price |
+ + + +
| 10 | printer | 20000 |
| 20 | keyboard | 20000 |
| 30 | monitor | 15000 |
| 40 | camera | 25000 |
+ + + +4 rows in set (0.00 sec)
Step 8: Perform saving and undoing
mysql> insert into product values
+ + + +
| pid | name | price |
+ + + +
| 10 | printer | 20000 |
| 20 | keyboard | 20000 |
| 30 | monitor | 15000 |
| 40 | camera | 25000 |
| 50 | mobile | 35000 |
| 60 | laptop | 70000 |
+ + + +6 rows in set (0.00 sec)
mysql> commit;
mysql> start
transaction;
mysql>savepoint s1;
values (80,'chair',25000);
+ + + +
| pid | name | price |
+ + + +
| 10 | printer | 20000 |
| 20 | keyboard | 20000 |
| 30 | monitor | 15000 |
| 40 | camera | 25000 |
| 50 | mobile | 35000 |
| 60 | laptop | 70000 |
| 70 | table | 50000 |
| 80 | chair | 25000 |
+ + + +8 rows in set (0.00 sec)
product;
+ + + +
| pid | name | price |
+ + + +
| 10 | printer | 20000 |
| 20 | keyboard | 20000 |
| 30 | monitor | 15000 |
| 40 | camera | 25000 |
| 50 | mobile | 35000 |
| 60 | laptop | 70000 |
+ + + +6 rows in set (0.00 sec)
PROGRAM NO -3
OBJECTIVE:
Altering a Table, Dropping/Truncating / Renaming a table, backing up/ Restoring aDatabase
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
Consider the library database with the following data and execute the queries
LIB(BID,TITLE,AUTHOR,PUBLICATION,YEAR OF PUBLICATION)
STEPS
3. Add a new column price with not null constraints to the existing table library
4. All the constraints and views that reference the column are dropped automatically along
withthe column.
8. Drop Table.
library001;mysql> use
library001;
mysql> create table lib (bid varchar(15) primary key, title varchar(20) not null, author
varchar(20), publication varchar(20),year_of_publication int(4));
mysql>desc lib;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| bid | varchar(15) | NO | PRI | NULL | |
| title | varchar(20) | NO | | NULL | |
| author | varchar(20) | YES | | NULL | |
| publication | varchar(20) | YES | | NULL | |
| year_of_publication | int | YES | | NULL | |
+ + + + + + +5 rows in set (0.00 sec)
Step 2.Rename the LIB as
rename to library1;mysql>desc
library1;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| bid | varchar(15) | NO | PRI | NULL | |
| title | varchar(20) | NO | | NULL | |
null;mysql>desc library1;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| bid | varchar(15) | NO | PRI | NULL | |
| title | varchar(20) | NO | | NULL | |
| author | varchar(20) | YES | | NULL | |
| publication | varchar(20) | YES | | NULL | |
| year_of_publication | int | YES | | NULL | |
| price | float(8,2) | NO | | NULL | |
+ + + + + + +6 rows in set (0.00 sec)
Step 4: All the constraints and views that reference the column are dropped automatically
along with the column.
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| bookid | varchar(15) | NO | PRI | NULL | |
| title | varchar(20) | NO | | NULL | |
| publication | varchar(20) | YES | | NULL | |
| year_of_publication | int | YES | | NULL | |
| price | float(8,2) | NO | | NULL | |
+ + + + + + +5 rows in set (0.00 sec)
Step 6: Insert Data into LIBRARY table
library1;
+ + + + + +
| bookid | title | publication | year_of_publication | price |
+ + + + + +
| sp001 | dbms | skyward_publishers | 2022 | 300.00 |
| sp002 | java | oxford_publishers | 2021 | 400.00 |
+ + + + + +2 rows in set (0.00 sec)
Step 7: Truncate table to
sec)
library1;mysql>desc
library1;
PROGRAM NO -4
OBJECTIVE:
For a given set of relation schemes, create tables and perform the following simple Queries,
Simple Queries with aggregate functions, Queries with aggregate functions (group by and
having clause)
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
STEPS
7. Dispaly employee information in ascending and descending order of their date of joining
10. Display the details of employee whose name is Rushank and salary is greater than 50000
mysql> create table salary (enovarchar(10) primary key, name varchar(20) not null, dept
varchar(10), doj date, salary float(10,2));
mysql>desc salary;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| eno | varchar(10) | NO | PRI | NULL | |
| name | varchar(20) | NO | | NULL | |
| dept | varchar(10) | YES | | NULL | |
| doj | date | YES | | NULL | |
| salary | float(10,2) | YES | | NULL | |
+ + + + + + +
+ + + + + +
| eno | name | dept | doj | salary |
+ + + + + +
| sc1010 | ahana | hr | 2015-02-10 | 60000.00 |
| sc1011 | ramesh | finance | 2010-03-12 | 45000.00 |
| sc1013 | naveen | marketing | 0008-01-09 | 55000.00 |
| sc1014 | anagha | hr | 2014-02-12 | 35000.00 |
| sc1015 | rushank | admin | 2016-05-11 | 55000.00 |
| sc1016 | rushank | finance | 2008-06-08 | 25000.00 |
+ + + + + +6 rows in set (0.00 sec)
+ +
| total_salary |
+ +
| 275000.00 |
+ +
1 row in set (0.04 sec)
Step 5: Find the sum and average salaries of employees of a particular department
+ + + +
| dept | total_salary | average_salary |
+ + + +
| hr | 95000.00 | 47500.000000 |
| finance | 70000.00 | 35000.000000 |
| marketing | 55000.00 | 55000.000000 |
| admin | 55000.00 | 55000.000000 |
+ + + +4 rows in set (0.06 sec)
Step 6: Find the number of employees working for each department.
+ + +
| dept | Number_of_Employees |
+ + +
| hr | 2|
| finance | 2|
| marketing | 1|
| admin | 1|
+ + +4 rows in set (0.00 sec)
Step 7: Display employee information in ascending and descending order of their date of
joining
+ + + + + +
| eno | name | dept | doj | salary |
+ + + + + +
| sc1013 | naveen | marketing | 0008-01-09 | 55000.00 |
+ +
| Highest Salary |
+ +
| 60000.00 |
+ +
1 row in set (0.10 sec)
Step 9: Find the least salary that an employee draws
+ +
| Least Salary |
+ +
| 25000.00 |
+ +
1 row in set (0.00 sec)
Step 10: Display the details of employee whose name is Rushank and salary is greater
than50000
mysql> select * from salary where name="rushank" and salary>50000;
+ + + + + +
| eno | name | dept |doj | salary |
+ + + + + +
| sc1015 | rushank | admin | 2016-05-11 | 55000.00 |
+ + + + +
+1 row in set (0.00 sec)
PROGRAM NO -5
OBJECTIVE :
Execute the fallowing queries
a. How the resulting salaries if every employee working on the ‘Research’ Departments is given
a 10% raise.
b. Find the sum of the salaries of all employees of the ‘Accounts’ department, as well as the
maximum salary, the minimum salary, and the average salary in this department
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
company001;mysql> use
company001;
mysql> create table dept ( dno int(4) primary key, dname varchar(20) not null, dlocation
varchar(20));
mysql> create table employee ( eno int(6) primary key, ename varchar(20) not null, edob date,
address varchar(20), gender varchar(6), salary int(10) not null, deptno int(4) references dept);
mysql> create table project (pno int(10) primary key, pname varchar(20) not null, dnum int(4)
references dept);
mysql> create table works_on ( eno int(6) references employee, pnum int(10) references
project,hours int(3), primary key (eno,pnum));
mysql>desc dept;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| dno | int | NO | PRI | NULL | |
| dname | varchar(20) | NO | | NULL | |
| dlocation | varchar(20) | YES | | NULL | |
+ + + + + + +3 rows in set (1.04 sec)
mysql>desc employee;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| eno | int | NO | PRI | NULL | |
| ename | varchar(20) | NO | | NULL | |
| edob | date | YES | | NULL | |
| address | varchar(20) | YES | | NULL | |
| gender | varchar(6) | YES | | NULL | |
| salary | int | NO | | NULL | |
| deptno | int | YES | | NULL | |
+ + + + + + +7 rows in set (0.06 sec)
mysql>desc project;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| pno | int | NO | PRI | NULL | |
| pname | varchar(20) | NO | | NULL | |
| dnum | int | YES | | NULL | |
mysql>descworks_on;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| eno | int | NO | PRI | NULL | |
| pnum | int | NO | PRI | NULL | |
| hours | int | YES | | NULL | |
+ + + + + + +3 rows in set (0.00 sec)
Insert the values into the tables:
dept;
+ + + +
| dno | dname | dlocation |
+ + + +
| 2 | accounts | jayanagar |
| 4 | research | kengeri |
| 5 | admin | southed |
+ + + +3 rows in set (0.00 sec)
mysql> insert into employee values (1001,'anirudh','1990-01-14','bangalore','male',45000,4);
01-26','dharwad','male',20000,4);
+ + + + + + + +
| eno | ename | edob | address | gender | salary | deptno |
+ + + + + + + -+
| 1001 | anirudh | 1990-01-14 | bangalore | male | 45000 | 4|
| 1002 | sinchana | 1990-12-22 | mangalore | female | 5000 | 2|
| 1003 | vinay | 1990-11-26 | hubli | male | 3000 | 2 |
| 1004 | lakshmi | 1998-03-04 | mysore | female | 5500 | 4|
| 1005 | vidya | 1978-11-26 | hubli | female | 35000 | 4|
| 1006 | prajwal | 1974-02-02 | bangalore | male | 65000 | 5|
| 1007 | prashant | 1989-01-26 | dharwad | male | 20000 | 4|
| 1008 | rajesh | 2010-02-10 | bangalore | male | 25000 | 2|
+ + + + + + + +8 rows in set (0.05 sec)
mysql> insert into project values (10,'erp',5);
mysql> insert into project values
(20,'banking',2);
mysql> insert into project values
(30,'connect_tech',4);mysql> insert into project
values (40,'smart_seek',5); mysql> insert into
project values (50,'finance',2); mysql> insert into
project values (60,'analysis',4);
mysql> insert into project values
(70,'market_research',4);mysql> insert into project
values (80,'smart_search',4); mysql> select * from
project;
+ + + +
| pno | pname | dnum |
+ + + +
| 10 | erp | 5|
| 20 | banking | 2|
| 30 | connect_tech | 4 |
| 40 | smart_seek | 5 |
| 50 | finance | 2|
| 60 | analysis | 4|
| 70 | market_research | 4 |
| 80 | smart_search | 4 |
+ + + +8 rows in set (0.00 sec)
mysql> insert into works_on values
(1001,10,4); mysql> insert into works_on
values (1002,10,6); mysql> insert into
works_on values (1003,10,4);
+ + + +
| eno | pnum | hours |
+ + + +
| 1001 | 10 | 4 |
| 1002 | 10 | 6 |
| 1003 | 10 | 4 |
| 1004 | 20 | 4 |
| 1005 | 20 | 8 |
| 1006 | 40 | 8 |
| 1007 | 50 | 8 |
| 1008 | 60 | 5 |
+ + +
+ 8 rows in
set (0.00 sec)
How the resulting salaries , if every employee working on the ‘research ’ departments is
given a 10% raise
+ + + + +
| max(e.salary) | min(e.salary) | sum(e.salary) | avg(e.salary) |
+ + + + +
| 25000 | 3000 | 33000 | 11000.0000 |
+ + + + +1 row in set (0.05 sec)
PROGRAM NO -6
OBJECTIVE :
Execute the fallowing queries
a. Retrieve the name of each employee Controlled by Department number 5 (use EXISTS
operator).
b. Retrieve the name of each dept and number of employees working in each Department which
has at least 2 employees
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
mysql> create database
company001;mysql> use
company001;
(a) Retrieve the name of each employee controlled by Department number 5 (use
EXISTSoperator )
mysql> select e.ename from employee e where exists (select d.dno from dept d where
e.deptno =d.dno and e.deptno='5');
+ +
| ename |
+ +
| prajwal |
+ +
(a) Retrieve the name of each dept and number of employees working in each
departmentwhich has at least 2 employees.
mysql> select d.dname, count(*) from employee e, dept d where e.deptno = d.dno group by
d.dname having count(*) >=2;
+ + +
| dname | count(*) |
+ + +
| research | 4|
| accounts | 3|
+ + +
2 rows in set (0.30 sec)
PROGRAM NO -7
OBJECTIVE :
Execute the fallowing queries
a. For each project, retrieve the project number, the project name, and the number of employee
who work on that project.(use GROUP BY)
b. Retrieve the name of employees who born in the year 1990’s
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
mysql> create database
company001;mysql> use
company001;
(a) For each project retrieve the project number, the project name and the number
ofemployees who work on that project. (use GROUPBY)
+ + + +
+ + + -+
| 10 | erp | 3|
| 20 | banking | 2|
| 40 | smart_seek | 1|
| 50 | finance | 1|
| 60 | analysis | 1|
+ + + +
mysql> select ename, edob from employee where edob like '1990-%%-%%';
+ + +
| ename | edob |
+ + +
| anirudh | 1990-01-14 |
| sinchana | 1990-12-22 |
| vinay | 1990-11-26 |
+ + +3 rows in set (0.04 sec)
PROGRAM NO -8
OBJECTIVE .
For each Department that has more than five employees, retrieve the department number and
number of employees who are making salary more than 40000.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
mysql> create database
company001;mysql> use
company001;
1. For each department that has more than five employees , retrieve the
departmentnumber and number of employees who are making salary more
than 40000.
+ + + +
| dname | dno | count(*) |
+ + + +
| research | 4 | 1 |
+ + + +1 row in set (0.00 sec)
2. For each department that has more than two employees , retrieve the
departmentnumber and number of employees who are making salary more than
40000.
mysql> select d.dname, d.dno, count(*) from employee e, dept d where e.deptno=d.dno and
salary>40000 and d.dno in ( select deptno from employee group by deptno having
count(*)>=2)group by d.dno,d.dname;
+ + + +
| dname | dno | count(*) |
+ + + +
| research | 4 | 1 |
| admin | 5 | 2 |
+ + + +2 rows in set (2.35 sec)
PROGRAM NO -9
OBJECTIVE . For each project on which more than two employees work, retrieve the project
number, project name and the number of employees who work on that project.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
+ + + +
| pno | pname | No_of_EMP_Working |
+ + + -+
| 10 | erp | 3|
+ + + +1 row in set (0.28 sec)
PROGRAM NO -10
OBJECTIVE :
For a given set of relation tables perform the following . Creating views (with and without
check option). Dropping views, Selecting from a view.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE
1. Without Check Option
mysql> insert into emp_dept( eno, ename, salary, deptno) values (1009,'srikanth',90000,5);
Step 1: Let us create simple view on EMP table with check option of salary less than
50000in where condition
mysql> create view emp_view as (select eno,ename,salary from employee where salary
<=50000) with check option;
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 '99999)' at line 1
PART B
PROGRAM NO -1
OBJECTIVE : Create the following tables with properly specifying Primary keys, Foreign
keys and solve the following queries.
BRANCH (Branchid, Branchname, HOD)
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
mysql> create table Branch (BRID INT PRIMARY KEY,BNAME VARCHAR(15)NOT
NULL,HOD VARCHAR(10));
-------+-------------+------+-----+---------+-------+
+-------+-------------+------+-----+---------+-------+
+-------+-------------+------+-----+---------+-------+
+---------+-------------+------+-----+---------+-------+
+---------+-------------+------+-----+---------+-------+
+---------+-------------+------+-----+---------+-------+
+---------+-------------+------+-----+---------+-------+
| AID | int(11) | NO | PRI | NULL | |
| ANAME | varchar(15) | YES | | NULL | |
| COUNTRY | varchar(15) | YES | | NULL | |
| AGE | int(11) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
• mysql> CREATE TABLE BOOK(BKID VARCHAR(10)PRIMARY
KEY,BNAME VARCHAR(15),AID VARCHAR(10)REFERENCES
AUTHOR,PUBLISHER VARCHAR(20),BRID INT REFERENCES BRANCH);
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| USN | varchar(15) | YES | | NULL | |
| BKID | varchar(10) | YES | | NULL | |
| BORROW_DATE | date | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
+-----+-----------+---------+------+
| AID | ANAME | COUNTRY | AGE |
+-----+-----------+---------+------+
| 123 | ARUNA | INDIA | 36 |
| 143 | SUMA | INDIA | 38 |
| 144 | SANGEETHA | INDIA | 42 |
| 145 | DILEEP | INDIA | 39 |
| 155 | SKHEKARP | INDIA | 44 |
+-----+-----------+---------+------+
5 rows in set (0.00 sec)
mysql> INSERT INTO
BOOK(BKID,BNAME,AID,PUBLISHER,BRID)VALUES('NEPDBMS','DBMS',123,'S
KYWARD',10);
Query OK, 1 row affected (0.14 sec)
mysql> COMMIT;
Query OK, 0 rows affected (0.00 sec)
PROGRAM NO -2
OBJECTIVE :
a. List the details of Students who are all studying in 2nd sem BCA.
b. List the students who are not borrowed any books.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
a. List the details of Students who are all studying in 2nd sem BCA.
mysql> SELECT *FROM STUDENT S,BRANCH BR WHERE
S.BRID=BR.BRID AND S.SEM='IISEM' AND BR.BNAME='BCA';
+------------+----------+-------------+------+-------+------+-------+----------+
| USN | NAME | ADDRESS | BRID | SEM | BRID | BNAME | HOD
|
+------------+----------+-------------+------+-------+------+-------+----------+
| SCAS202201 | ANURADHA | JAYANAGAR | 10 | IISEM | 10 | BCA |
SANTHOSH |
| SCAS202202 | MANJULA | BASAVANGUDI | 10 | IISEM | 10 | BCA |
SANTHOSH |
+------------+----------+-------------+------+-------+------+-------+----------+
3 rows in set (0.04 sec)
PROGRAM NO -3
OBJECTIVE :
a. Display the USN, Student name, Branch_name, Book_name, Author_name,
Books_Borrowed_ Date of 2nd sem BCA Students who borrowed books.
b. Display the number of books written by each Author.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
mysql> SELECT
S.USN,S.NAME,S.SEM,BR.BNAME,BK.BKNAME,A.ANANE,B.BORROW_DATE FROM
STUDENT S,BRANCH BR,BOOK BK,AUTHOR A,BORROW B,WHERE S.BRID=BR.BRID
AND S.BRID=BK.BRID AND A.AID=BK.AID AND B.USN=S.USN AND
BK.BKID=B.BKID AND S.SEM='IISEM' AND BR.BNAME='BCA';
b. Display the number of books written by each Author
mysql> SELECT A.ANAME,COUNT(DISTINCT BK.BKID)AS "NO OF
BOOKS" FROM AUTHOR A,BOOK BK WHERE A.AID=BK.AID GROUP BY A.ANAME;
+-----------+-------------+
| ANAME | NO OF BOOKS |
+-----------+-------------+
| ARUNA | 1|
| DILEEP | 1|
| SANGEETHA | 1|
+-----------+-------------+
3 rows in set (0.05 sec)
PROGRAM NO -4
OBJECTIVE :
a. Display the student details who borrowed more than two books.
b.Display the student details who borrowed books of more than one Author.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
mysql> SELECT S.NAME FROM STUDENT S,BORROW B WHERE S.USN=B.USN
GROUP BY S.NAME HAVING COUNT(DISTINCT B.BKID)>2;
Empty set (0.00 sec)
b.Display the student details who borrowed books of more than oneAutho
mysql> SELECT S.NAME,COUNT(DISTINCT BK.AID)FROM STUDENT S,BOOK
BK,BORROW B WHERE S.USN=B.USN AND B.BKID=BK.BKID GROUP BY S.NAME
HAVING COUNT(DISTINCT BK.AID)>1;
Empty set (0.00 sec)
PROGRAM NO -5
OBJECTIVE :
a. Display the Book names in descending order of their names.
b. List the details of students who borrowed the books which are all published by the same
publisher.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
a. Display the Book names in descending order of their names.
mysql> SELECT *FROM BOOK ORDER BY BNAME DESC;
+----------+-------+------+-----------+------+
| BKID | BNAME | AID | PUBLISHER | BRID |
+----------+-------+------+-----------+------+
| NEPMATHS | MATHS | 145 | OXFORD | 20 |
| NEPJAVA | JAVA | 144 | SKYWARD | 20 |
| NEPDBMS | DBMS | 123 | SKYWARD | 10 |
+----------+-------+------+-----------+------+
3 rows in set (0.00 sec)
b. List the details of students who borrowed the books which are all published by the same
publisher. Consider the following schema: STUDENT (USN, name, date_of_birth, branch,
mark1, mark2, mark3, total, GPA
PROGRAM NO -6
OBJECTIVE :
Consider the following schema:
STUDENT (USN, name, date_of_birth, branch, mark1, mark2, mark3, total, GPA)
Perform the following: a. Creating Tables (With and Without Constraints),
Inserting/Updating/Deleting Records in a Table, Saving (Commit) and Undoing (rollback)
.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
a. Creating Tables (With and Without Constraints),Inserting/Updating/Deleting Records in a
Table, Saving (Commit) and Undoing (rollback)
+--------+-------------+------+-----+---------+-------+
9 rows in set (0.07 sec)
• Inserting records into the table
mysql> COMMIT;
Query OK, 0 rows affected (0.00 sec)
• Deleting records from table and saving
+-----------+---------+------------+--------+-------+-------+-------+-------+-
-----+
5 rows in set (0.00 sec)
Updating Records in atable
mysql> update students set total=marki+mark2+mark3;
Query OK, 5 rows affected (0.12 sec)
Rows matched: 5 Changed: 5 Warnings: 0
PROGRAM NO -7
OBJECTIVE :
Execute the following queries:
a. Find the GPA score of all the students.
b. Find the students who born on a particular year of birth from the date_of_birth column.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE:
a. Find the GPA score of all the students.
b. Find the students who born on a particular year of birth from the date_of_birth column.
+-----------+---------+------------+--------+-------+-------+-------+-------+-
-----+
| usn | name | dob | branch | marki | mark2 | mark3 | total |
gpa |
+-----------+---------+------------+--------+-------+-------+-------+-------+-
-----+
| sca202204 | bhavana | 2022-04-06 | ba | 85 | 96 | 97 | 278 |
9|
+-----------+---------+------------+--------+-------+-------+-------+-------+-
-----+
1 row in set (0.00 sec)
PROGRAM NO -8
OBJECTIVE :
a. List the students who are studying in a particular branch of study.
b. Find the maximum GPA score of the student branch-wise.
PROCEDURE:
1. Create: Open MYAQL, write the query.
2. Execute: Press Enter.
SOURCE CODE: