0% found this document useful (0 votes)
27 views

Assignment 1: A) Create The Tables With The Appropriate Integrity Constraints

The document contains the details of four assignments involving creating database tables, inserting sample data, and writing SQL queries to retrieve and summarize data. Assignment 1 involves tables for customers, items, and sales with queries to list bills, totals, customers spending over $50, items purchased by a customer, and views. Assignment 2 similarly involves tables for students, memberships, books, and records with associated queries. Assignments 3 and 4 follow a similar structure of setting up tables and queries for employee payroll and customer cassette rentals respectively.

Uploaded by

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

Assignment 1: A) Create The Tables With The Appropriate Integrity Constraints

The document contains the details of four assignments involving creating database tables, inserting sample data, and writing SQL queries to retrieve and summarize data. Assignment 1 involves tables for customers, items, and sales with queries to list bills, totals, customers spending over $50, items purchased by a customer, and views. Assignment 2 similarly involves tables for students, memberships, books, and records with associated queries. Assignments 3 and 4 follow a similar structure of setting up tables and queries for employee payroll and customer cassette rentals respectively.

Uploaded by

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

ASSIGNMENT 1

a) Create the tables with the appropriate integrity constraints


• create table Customer( Cust_id int(20)primary key,Cust_name varchar(30));
• create table item( item_id int(20)primary key,item_name varchar(30), price
numeric(10,2));


create table sale( bill_no int(20)primary key,bill_date varchar(30),Cust_id int(20),
item_id int(20), foreign key (Cust_id) references Customer (Cust_id), foreign key
(item_id) references item (item_id), qty_sold int(20));

b) Insert around 10 records in each of the table.

• insert into Customer


values(1,'aaa'),(2,'bbb'),(3,'ccc'),(4,'ddd'),(5,'eee'),(6,'fff'),(7,'ggg'),(8,'hhh'),(9,'ggg'),(10,
'hhh');

• insert into item values


(11,'AAA',10),(22,'BBB',20),(33,'CCC',30),(44,'DDD',40),(55,'EEE',50),(66,'FFF',60),
(77,'GGG',70),(88,'HHH',80),(99,'III',90),(1010,'JJJ',100);

• insert into sale values (102,'2019-10-08',2,22,20), (103,'2019-10-08',3,33,30),


(104,'2019-10-07',4,44,40),
(105,'2019-10-08',5,55,50),(106,'2019-10-11',6,66,60),(107,'2019-10-08',7,77,70),
(108,'2019-10-08',8,88,80),(109,'2019-10-08',9,99,90),
(110,'2019-10-10',10,1010,100),(111,'2019-10-11',2,44,5);

c) List all the bills for the current date with the customer names
and item numbers.

• select
Cust_name,item_id from sale natural join Customer where bill_date='2019-10-08';
d)List the total Bill details with the quantity sold, price of the item and the final
amount

• select bill_no,bill_date,Cust_id,Cust_name,item_id,item_name, qty_sold,


price,(qty_sold*price) as total from sale natural join item natural join Customer;
e)List the details of the customer who have bought a product which has a price>50

• select Cust_id,Cust_name from sale natural join item natural join Customer
where price>50;

f)Give a count of how many products have been


bought by each customer

• select Cust_id, Cust_name, count(Cust_name)


from sale natural join Customer group by Cust_id;

g)Give a list of products bought by a customer having cust_id as 2

• select item_name from sale natural join item where Cust_id=2;


i)Create a view which lists out the bill_no, bill_date, cust_id, item_id, price,
qty_sold, amountCreate a view which lists the daily sales date wise for the last one
week

• select bill_no, bill_date, Cust_id, item_id,qty_sold,price,


(qty_sold*price) as amount from sale natural join item
order by bill_date asc;

ASSIGNMENT 2
a)Create the tables with the appropriate integrity constraints
• create table student(Stud_no int(10) primary key, Stud_name varchar(20));
• create Membership(Mem_no int(10) primary key, Stud_no int(10));
• create table Book(book_no int(10) primary key, book_name varchar(20),
author varchar(20));
• create table Iss_rec(iss_no int(10) primary key, iss_date date,
Mem_no int(10), book_no int(10),
foreign key(Mem_no) references Membership(Mem_no),
foreign key(book_no) references Book(book_no));

b)Insert around 10 records in each of the tables


• insert into student values(1,'A'),(2,'B'),(3,'C'),(4,'D'),(5,'E'),(6,'F'),(7,'G'),(8,'H'),(9,'I'),(10,'J');
• insert into Membership values(11,1),(22,2),(33,3),(44,4),(55,5),(66,6),
(77,7),(88,8),(99,9),(110,10);
• insert into Book
values(101,'a','AA'),(202,'b','BB'),(303,'c','CC'),(404,'d','DD'),(505,'e','EE'),(606,'f','FF'),(707,'
g','GG'),(808,'h','HH'),(909,'i','II'),(110,'j','JJ');
• insert into Iss_rec values(111,'2019-10-02',22,303),(112,'2019-10-02',33,404),
(113,'2019-10-03',11,303),(114,'2019-10-03',66,707),
(115,'2019-10-05',99,606),(116,'2019-10-06',88,101),
(117,'2019-10-06',110,909),(118,'2019-10-08',55,101),
(119,'2019-10-10',22,404),(120,'2019-10-11',11,404);

c)List all the student names with their membership numbers


• select Stud_name, Mem_no from Membership natural join student;
d)List all the issues for the current date with student and Book names
• select iss_no, iss_date,Mem_no, Stud_name, book_no, book_name from Iss_rec
natural join book
natural join Membership natural join student
where iss_date='2019-10-06';

e)List the details of students who borrowed book whose author is DD


• select iss_no, iss_date,Mem_no, Stud_name from Iss_rec natural join Book natural join
Membership natural join student where author='DD';

f)Give a count of how many books have been bought by each student
• select Stud_name, count(Stud_no) from Iss_rec natural join Book natural join
Membership natural join student group by Stud_no;
g)Give a list of books taken by student with stud_no as 2
• select iss_no, iss_date,book_no, book_name from Iss_rec natural join Book natural join
Membership natural join student where Stud_no=2;

h)List the book details which are issued as of today


• select book_no, book_name from Iss_rec natural join Book natural join Membership
natural join student where iss_date='2019-10-06';

i)Create a view which lists out the iss_no, iss _date, stud_name, book name
• select iss_no, iss_date,Stud_name, book_name from Iss_rec natural join Book natural
join Membership natural join student;
j)Create a view which lists the daily issues-date wise for the last one week
• select iss_no, iss_date, Mem_no, Stud_name, book_no, book_name from
Iss_rec natural join Book natural join Membership natural join student
order by iss_date asc;

assignment 4

a.) create table customer(cust_no int(10),cust_name varchar(20),primary key(cust_no));

create table membership(mem_no int(10),cust_no int(10),primary key(mem_no),foreign key(cust_no)


references customer(cust_no));

create table cassette(cass_no int(10) ,case_name varchar(20),language varchar(20),primary key(cass_no));

b.)
c.) select cust_name,mem_no from customer natural join membership;
d.) select case_name,cust_name from iss_rec natural join cassette natural join membership natural join
customer where iss_rec.iss_date='2019-10-05';

e)select cust_no,cust_name from iss_rec natural join cassette natural join membership natural join
customer where case_name="ecst";

f.)select cust_no,cust_name,count(cust_no) from iss_rec natural join membership natural join customer
group by cust_no;

g)

select cass_no,case_name from iss_rec natural join cassette natural join membership natural join customer
where mem_no=15;

h)

select cass_no from iss_rec natural join cassette where iss_rec.iss_date='2019-10-05';

i)

create view detail as select iss_no, iss_date, cust_name, case_name from iss_rec natural join cassette
natural join membership natural join customer;

assignment 3

a)

create table employee (emp_id int(10),emp_name varchar(20) ,primary key (emp_id));

create table department(dept_id int(10),dept_name varchar(20), primary key (dept_id));

create table paydetails(emp_id int(10),dept_id int(10),basic int(10),deductions int(10),additions int(10),doj


date,primary key(emp_id,dept_id),foreign key(emp_id) references employee(emp_id),foreign key(dept_id)
references department(dept_id));

create table payroll(emp_id int(10),pay_date date,primary key(emp_id,pay_date),foreign key(emp_id)


references employee(emp_id));

b)
c)

select emp_id,dept_id from paydetails;


d)

select emp_id,emp_name from paydetails natural join employee where doj='2019-10-01';

e)

select emp_id,emp_name from paydetails natural join employee where paydetails.basic between 10000
and 20000;

f)

select dept_id, count(emp_id) from paydetails group by dept_id;


g)select emp_id,emp_name from paydetails natural join employee where
paydetails.basic+paydetails.additions-paydetails.deductions>10000;

h)

select emp_id,emp_name from employee where emp_id=5;

i)

create view sho as select emp_name,dept_name,basic,deductions from paydetails natural join department
natural join employee;

j)

create view list as select emp_name,basic-deductions+additions as netsalary from paydetails natural join
employee;

You might also like