Dbms Lab Internal 1
Dbms Lab Internal 1
QUESTION 1
SOLUTUON
CREATE DATABASE MyDb1 ;
USE MyDb1 ;
Fname VARCHAR(255),
Minit VARCHAR(1),
Lname VARCHAR(255),
Bdate DATE,
Address VARCHAR(255),
Sex VARCHAR(1),
Salary DECIMAL(10,2),
Super_ssn VARCHAR(9),
Dno INT,
);
-- Insert data into the EMPLOYEE table
('John', 'D', 'Doe', '123456789', '1990-05-15', '123 Main St', 'M', 50000.00, '987654321', 1),
('Jane', 'A', 'Smith', '987654321', '1985-08-22', '456 Oak St', 'F', 60000.00, NULL, 2),
('Bob', 'J', 'Johnson', '555555555', '1992-11-10', '789 Pine St', 'M', 45000.00, '123456789', 1),
('Alice', 'M', 'Williams', '111111111', '1988-04-03', '101 Elm St', 'F', 55000.00, '987654321', 3),
('Charlie', 'R', 'Brown', '999999999', '1995-09-20', '202 Maple St', 'M', 70000.00, '123456789', 2);
Dname VARCHAR(255),
Mgr_san VARCHAR(9),
Mgr_start_date DATE,
);
Dlocation VARCHAR(255),
);
(3, 'Chicago');
Pname VARCHAR(255),
Plocation VARCHAR(255),
Dnum INT,
);
);
Dependent_name VARCHAR(255),
Sex VARCHAR(1),
Bdate DATE,
Relationship VARCHAR(255),
);
QUESTION 2
1. To Create a table called reserves table and answer the following queries
Reserves(sid: integer, bid: integer, day: date)
sid INTEGER,
bid INTEGER,
day DATE
);
QUESTION 4
1. Retrieve details of all books in the library – id, title, name of publisher, authors, number of copies in
each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan 2017 to Jun
2017
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data manipulation
operation.
SOLUTUON
-- Create tables
Title VARCHAR(255),
Publisher_Name VARCHAR(255),
Pub_Year INT
);
Book_id INT,
Author_Name VARCHAR(255),
);
(1, 'Author1'),
(2, 'Author2'),
(2, 'Author3'),
(3, 'Author4');
Address VARCHAR(255),
Phone VARCHAR(20)
);
Book_id INT,
Branch_id INT,
Noof_Copies INT,
);
(1, 1, 5),
(1, 2, 3),
(2, 1, 2),
(3, 2, 4);
Book_id INT,
Branch_id INT,
Card_No INT,
Date_Out DATE,
Due_Date DATE,
);
Branch_Name VARCHAR(255),
Address VARCHAR(255)
);
SELECT
B.Book_id,
B.Title,
B.Publisher_Name,
BA.Author_Name,
BC.Branch_id,
BC.Noof_Copies
FROM
BOOK B
JOIN
JOIN
-- Query 2: Get particulars of borrowers who have borrowed more than 3 books from Jan 2017 to Jun 2017
SELECT
BL.Card_No,
COUNT(BL.Book_id) AS Books_Borrowed
FROM
BOOK_LENDING BL
WHERE
GROUP BY
BL.Card_No
HAVING
COUNT(BL.Book_id) > 3;
-- Query 3: Delete a book in the BOOK table and update related tables
BEGIN
BEGIN
END
ELSE
BEGIN
END;
END;
QUESTION 5
2. Find the name and numbers of all salesmen who had more than one customer.
3. List all salesmen and indicate those who have and don’t have customers in their cities (Use UNION
operation.)
SOLUTUON
-- Create tables
Name VARCHAR(255),
City VARCHAR(255),
Commission DECIMAL(5, 2)
);
Cust_Name VARCHAR(255),
City VARCHAR(255),
Grade INT,
Salesman_id INT,
Ord_Date DATE,
Customer_id INT,
Salesman_id INT,
);
-- SALESMAN
-- CUSTOMER
-- ORDERS
FROM CUSTOMER
WHERE Grade > (SELECT AVG(Grade) FROM CUSTOMER WHERE City = 'Bangalore');
-- Query 2: Find the name and numbers of all salesmen who had more than one customer
FROM SALESMAN S
-- Query 3: List all salesmen and indicate those who have and don’t have customers in their cities (Use UNION operation)
FROM SALESMAN S
UNION
FROM SALESMAN S