Practicle File SQL Faculty: MR Surendra Namdeo

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 18

Practicle File

SQL

Faculty : Mr Surendra Namdeo

Submitted By :
Shiraz Khan
MCA II sem
Question 1:- Consider the relationship EMPLOYEE

Attributes are:

E_id Varchar2(20),
F_Name Varchar2(15),
M_Name Varchar2(15),
L_Name Varchar2(20),
Address Varchar2(100),
Salary Number(10,2),
Date_of_Birth Date

Where address field contain the value in following format


<House_No>;<Street>;<Colony>;<City>;<State>;<Pincode>;
i.e. F-189;Near Ram Mandir;M.P.Nagar;Bhopal;M.P.;462002;

Answer:-

Create.sql :-

create table szk_employee


(e_id varchar2(20),f_name varchar2(15),m_name varchar2(15),l_name varchar2(20),address
varchar2(100),salary number(10,2),date_of_birth date)
check (e_id like 'E-%');

desc szk_employee;
commit;

create table szk_employee


(e_id varchar2(20) check (e_id like 'E-%'),f_name varchar2(15),m_name varchar2(15),l_name
varchar2(20),address varchar2(100),salary number(10,2),date_of_birth date);

Insert.sql :-

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0002', 'Mohd', 'Shiraz', 'Khan', '175;31;Sharda Nagar Colony;Bhopal;M.P.;462001','40000', '23-dec-
1983');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0001', 'Syed', 'Zamran', 'Husain', '31;001;Guru Nanak Colony;Bhopal;M.P.;462001','70000', '09-jan-
1985');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0003', 'Mrs', 'Nandini', 'Sharma', '11;1;Gandhi Nagar Colony;Bhopal;M.P.;462001','9000', '01-feb-
1980');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0004', 'Mrs', 'Pushpa', 'Dewi', '19;07;Prem Nagar Colony;Bihar;U.P.;422007','10500', '21-feb-1950');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0005', 'Mr', 'kamlesh', 'Jhadav', '19;07;Lalu Nagar Colony;Bihar;U.P.;422007','10500', '28-mar-
1960');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0006', 'Mohd', 'Jamal', 'Khan', '15;5;Arera Colony;Bhopal;M.P.;462001','10001', '07-jan-1982');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0007', 'Mohd', 'Junaid', 'Khan', '115;4;Itwaqra Nagar Colony;Bhopal;M.P.;462001','40000', '21-jul-
1984');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0008', 'Mohd', 'faiz', 'Khan', '75;6;Mubaiya Nagar Colony;Bhopal;M.P.;462001','12000', '2-dec-
1980');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0009', 'Mr', 'Deepak', 'Nath', '17;4;Ambani Colony;Gwalior;M.P.;462005','13000', '23-nov-1973');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0010', 'Mrs', 'Anjlina', 'Jolie', '007;07;OLd Model Colony;Mumbai;Mhr.;462881','150', '1-apr-1979');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0011', 'Mr', 'Ricky', 'Martin', '006;06;Old Model Colony;Mumbai;Mhr.;462881','10001', '2-apr-1980');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0012', 'Mohd', 'Tom', 'Cruice', '09;06;Film Colony;Agra;M.P.;462007','10003', '17-jul-1960');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0013', 'Mr', 'Sunder', 'Yadav', '1;04;Rabdi Nagar Colony;Bihar;U.P.;421007','10200', '28-may-1950');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0014', 'Sir', 'Don', 'Brademan', '7;4;Mahatma Nagar Colony;Gujrat;M.P.;421034','10001', '28-may-
1879');

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0015', 'Mr', 'Tarun', 'Sharma', '23;111;TT Nagar;Bhopal;M.P.;421014','1700', '18-may-1979');
commit;

constraint .sql :-

alter table szk_employee


add constraint pk_em primary key (e_id);

Drop table.sql :-

drop table szk_employee;


querries.sql :-

Q1:- Get employee number of employees who belong to the U.P.

select * from szk_employee


where substr(address, instr(address,';',1,4)+1, instr(address,';',1,5)-(instr(address,';',1,4))-1) like 'U.P.';

Q2:- Get Full Names of employees, concatenate the column F_Name, M_Name and
L_Name. Rename the new column heading as ‘FULL NAME’.

select concat(concat(concat(concat(f_name,' '),m_name),' '),l_name) "Full Name" from szk_employee;

Q3:- Find out the youngest and oldest person from employee table.

(select b.m_name,b.date_of_birth from


szk_employee a, szk_employee b
where a.date_of_birth < b.date_of_birth
minus
select b.m_name,b.date_of_birth from
szk_employee a, szk_employee b
where a.date_of_birth > b.date_of_birth)

union

(select b.m_name,b.date_of_birth from


szk_employee a, szk_employee b
where a.date_of_birth > b.date_of_birth
minus
select b.m_name,b.date_of_birth from
szk_employee a, szk_employee b
where a.date_of_birth < b.date_of_birth);

Q4:- Get employee id and name that belong to the Bhopal city.

select * from szk_employee


where substr(address, instr(address,';',1,3)+1,
instr(address,';',1,4)-(instr(address,';',1,3))-1) like 'Bhopal';

Q5:- Get employee name and date of birth. (Date of Birth should be in format
‘DD/MM/YY HH:MI:SS’)

select concat(concat(concat(concat(f_name,' '),m_name),' '),l_name)"Full


Name",to_char(date_of_birth,'dd/mm/yy hh:mi:ss')"BirthDay" from szk_employee;

Q6:- Delete all employees from employee where city is Bhopal.

delete szk_employee
where substr(address, instr(address,';',1,3)+1,
instr(address,';',1,4)-(instr(address,';',1,3))-1) like 'Bhopal';

Q7:- List all the employees who are located in ‘TT NAGAR’ colony.
select * from szk_employee
where substr(address, instr(address,';',1,2)+1,
instr(address,';',1,3)-(instr(address,';',1,2))-1) like 'TT Nagar';

Q8:- Find the names of all employees having ‘S’ as the first letter in their names.

select concat(concat(concat(concat(f_name,' '),m_name),' '),l_name) "Full Name" from szk_employee


where(concat(concat(concat(concat(f_name,' '),m_name),' '),l_name) Like 'S%') ;

Q9:- Find the list of all employees whose salary is greater than value 10,000.

select * from szk_employee


where (salary>'10000');

Q10:- Insert one row into employee table. Where DOB is ‘10/Dec/1987 18:20:23’.

insert into szk_employee


(e_id, f_name, m_name, l_name, address, salary, date_of_birth)
values ('E-0016', 'Mohd', 'Mohnish', 'Khan', '155;32;Kargar Nagar Colony;Bhopal;M.P.;462001','10000', '10-
dec-1987 18:20:23');
Question 2 :-Below is a format of tables, creates it and does the related queries given.

CLIENT_MASTER (client_no#, name, address, city, pincode, state, bal_due).

PRODUCT_MASTER (product_no, description, sell_price, cost_price).

SALESMAN_MASTER (salesman_no, name, address, city, remark).

SALES_ORDER (order_no, order_date, client_no, salesman_no, order_status).

SALES_ORDER_DETAIL (order_no, product_no, qty_ordered, qty_disp, product_rate).

Answer:-

Create.sql :-

create table szk_client_master


(client_no varchar2(10) check (client_no like 'C-%'), name varchar2(20), address varcahr2(30), city
varchar2(10), pincode varchar(7),state varchar(15), bal_due number(10,2));

create table szk_product_master


(product_no varchar(10) check (product_no like 'P-%'), description varchar(30), sell_price number(10,2),
cost_price number(10,2));

create table szk_salesman_master


(salesman_no varchar(5) check (salesman_no like 'SM-%'), name varchar(20), address varchar(40), city
varchar2(10), remark varchar(30));

create table szk_sales_order


(order_no varchar(10) check (order_no like 'O%'), order_date date, client_no varchar(5), salesman_no
varchar(5), order_status varchar(10));

create table szk_s_odr_detail


(order_no varchar(10), product_no varchar(5), qty_order varchar(4), qty_disp varchar(4), product_rate
number(10,2));

commit;

insert.sql :-

insert into szk_client_master


(client_no, name, address, city, pincode, state, bal_due)
values ('C-0002', 'Shiraz', '178 Sharda Nagar','Bhopal', '462001','M.P.', '50000');

insert into szk_client_master


(client_no, name, address, city, pincode, state, bal_due)
values ('C-0001', 'Zamran', '31 Guru Nanak Colony','Bhopal', '462001','M.P.', '70000');

insert into szk_client_master


(client_no, name, address, city, pincode, state, bal_due)
values ('C-0003', 'Amit', '1 Parag Nanak Colony','Indore', '442001','M.P.', '10000');

insert into szk_client_master


(client_no, name, address, city, pincode, state, bal_due)
values ('C-0004', 'Sania', '30 idgah hill Colony','Bhopal', '462001','M.P.', '40000');

insert into szk_client_master


(client_no, name, address, city, pincode, state, bal_due)
values ('C-0005', 'sachin', '12 broke Bond Colony','Bombay', '542001','Maharastra', '25000');

insert into szk_product_master


(product_no, description, sel_price, cost_price)
values ('P-0001', '1.22 Floppy', '1100', '1000');

insert into szk_product_master


(product_no, description, sel_price, cost_price)
values ('P-0002', '1.44 Floppy', '1200', '1100');

insert into szk_product_master


(product_no, description, sel_price, cost_price)
values ('P-0003', 'CD Drive', '8000', '6000');

insert into szk_product_master


(product_no, description, sel_price, cost_price)
values ('P-0004', 'Combo Drive', '10000', '8000');

insert into szk_product_master


(product_no, description, sel_price, cost_price)
values ('P-0005', '80 GB Hard Disk', '7000', '5000');

insert into szk_salesman_master


(salesman_no , name, address, city, remark);
values ('SM-0001', 'Amitesh', '11 Bond Colony','Bombay', '542001','Good');

insert into szk_salesman_master


(salesman_no , name, address, city, remark);
values ('SM-0002', 'Imran','13 Guru govind Colony', 'Indore', '442001', 'Excellent');

insert into szk_salesman_master


(salesman_no , name, address, city, remark);
values ('SM-0003', 'Madan, '111 Nehru Colony', 'Bhopal', '462001', 'Very Good');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O000001', '10-jan-2006', 'C-0005', 'SM-0003', 'Wait');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O190012', '18-mar-2006', 'C-0001', 'SM-0002', 'Deliver');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O000002', '11-jan-2006', 'C-0004', 'SM-0003', 'Wait');
insert into szk_sales_order
(order_no, order_date, client_no, salesman_no, order_status)
values ('O000003', '21-feb-2006', 'C-0002', 'SM-0001', 'Wait');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O000004', '19-mar-2006', 'C-0003', 'SM-0002', 'Deliver');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O000005', '22-feb-2006', 'C-0001', 'SM-0002', 'Deliver');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O000006', '15-mar-2006', 'C-0001', 'SM-0002', 'Deliver');

insert into szk_sales_order


(order_no, order_date, client_no, salesman_no, order_status)
values ('O000007', '25-mar-2006', 'C-0001', 'SM-0002', 'Deliver');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000001', 'P-0001', '1', '1.22 Floppy', '1100');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O190012', 'P-0003', '3', 'CD Drive', '8000');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000002', 'P-0001', '2', '1.22 Floppy', '1100');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000003', 'P-0005', '1', '80 GB Hard Disk', '7000');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000004', 'P-0001', '1', '1.22 Floppy', '1100');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000005', 'P-0004', '3', 'Combo Drive', '10000');
insert into szk_s_odr_detail
(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000006', 'P-0003', '2', 'CD Drive', '8000');

insert into szk_s_odr_detail


(order_no, product_no, qty_order, qty_disp, product_rate)
values ('O000007', 'P-0005', '5', '80 GB Hard Disk', '7000');
primarykey.sql:-

alter table szk_client_master


add constrain pk_cm primary key (client_no);

alter table szk_product_master


add constrain pk_pm primary key (product_no);

alter table szk_salesman_master


add constrain pk_smm primary key (salesman_no);

alter table szk_sales_order


add constraint pk_soo primary key (order_no);

foreignkey.sql:-

alter table szk_sales_order


add constraint fk_soc foreign key client_no
references szk_client_master (client_no));

alter table szk_sales_order


add constraint fk_sosm foreign key salesman_no
references szk_salesman_master (salesman_no));

alter table szk_s_odr_detail


add constraint fk_sodo foreign key order_no
references szk_sales_order (order_no));

alter table szk_s_odr_detail


add constraint fk_sodp foreign key product_no
references szk_product_master (product_no));

drop constraint.sql :-

alter table szk_sales_order


drop constraint fk_soc;

alter table szk_sales_order


drop constraint fk_sosm;

alter table szk_s_odr_detail


drop constraint fk_sodo;

alter table szk_s_odr_detail


drop constraint fk_sodp;

drop table.sql:-

drop table szk_client_master;

drop table szk_product_master;


drop table szk_salesman_master;

drop table szk_sales_order;

drop table szk_s_odr_detail;

queries.sql :-

Q1:- List the entire client who are located in BHOPAL city.

select * from szk_client_master


where city='Bhopal';

Q2:- Change the cost price of ‘1.22 FLOPPIES’ to 948.65.

update szk_product_master
set cost_price='948.65'
where description='1.22 Floppy';

Q3:- List the names, city and pin code of clients who are not in the state of ‘Maharastra’.

select name, city, pincode, from szk_client_master


where not state='Maharastra';

Q4:- Determine the maximum and minimum product prices, Rename the output as
Max_Rate and Min_Rate respectively.

select max(sell_price) "Max-Rate", min(sell_price)'Min_Rate"


from szk_product_master;

Q5:- Find the date, 15 days after today’s date.

select sysdate+15 from dual;

Q6:- Display the order_date in the format ‘DD-Month-YYYY’ e.g. 12-May-2004’.

select to_char(order_date, 'dd-month-yyyy') "Order Date"


from szk_sales_order;

Q7:- Print the description and total qty sold for each product.

 select qty_disp,sum(qty_order)”Sum” from zh_s_odr_detail


group by qty_disp;

Q8:- Find the names of clients who have purchased ‘CD Drive’.

select c.name from szk_client_master c, zh_sales_order s, szk_s_odr_detail so


where so.qty_disp='CD Drive'
and
c.client_no=s.client_no and s.order_no=so.order_no;
Q9:- Find the product_no, and description of non-moving products. i.e. products not being
sold.

(select product_no, description from szk_product_master)


minus
(select distinct product_no, qty_disp from szk_s_odr_detail);

Q10:- Find the customer_name and address for the client who has placed order no.
‘O190012’.

select c.name, c.address from szk_client_master c, szk_sales_order s


where s.order_no='O190012'
and
c.client_no=s.client_no;

Q11:- Find the names of clients who have placed orders worth Rs. 10,000 or more.

select name from zh_client_master


where (client_no in (select client_no from zh_sales_order
where (order_no in (select order_no from zh_s_odr_detail
group by order_no
having sum(product_rate)>10000))));

Q12:- Find out the products, which have been sold to ‘AMIT’.

select pm.product_no, pm.description


from szk_client_master c, szk_sales_order s, szk_s_odr_detail so, szk_product_master pm
where c.name='Amit'
and c.client_no=s.client_no and s.order_no=so.order_no and pm.product_no=so.product_no;
Question 3:-
STUDENT (roll_no, name, year, branch)
SUBJECT (sub_code, sub_name, class_hour, department)
INSTRUCTOR (instructor_id, name)
SECTION (secidentifer, sub_code, semester, year, instructor_id)
GRADE_REPORT (roll_no, secidentifier, grade);

create.sql:-

create table szk_student


(roll_no varchar(13) check (roll_no like '0112CA0510__'), name varchar2(20), year varchar(4), branch
varchar(10));

create table szk_subject


(sub_code varchar(6), sub_name varchar(30), class_hours varchar(20), department varchar(10));

create table szk_instructor


(instructor_id varchar(10) check (instructor_id like 'I-%'), name varchar(20));

create table szk_section


(secidentifer varchar(10), sub_code varchar(6), semester varchar(5), year varchar(2), instructor_id varchar(10));

create table szk_grade_report


(roll_no varchar(13), secidentifier varchar(10), grade varchar(4));

commit;

insert.sql:-

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051040', 'Shiraz Khan', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051058', 'Zamran Husain', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051043', 'Smita Dubey', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051042', 'Shweta Sengar', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051052', 'Varuna Sharma', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051016', 'Harish Singh', 'I', 'MCA');
insert into szk_student
(roll_no, name, year, branch)
values ('0112CA051005', 'Anshul Gite', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051003', 'Amit Gupta', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051032', 'Priyanka Soni', 'I', 'MCA');

insert into szk_student


(roll_no, name, year, branch)
values ('0112CA051028', 'Pawan Dubey', 'I', 'MCA');

insert into szk_subject


(sub_code, sub_name, class_hours, department)
values('201','Operating System', '8:00am-9:00am', 'CA');

insert into szk_subject


(sub_code, sub_name, class_hours, department)
values('202','DBMS', '9:00am-10:00am', 'CA');

insert into szk_subject


(sub_code, sub_name, class_hours, department)
values('203','Data Structure', '10:00am-11:00am', 'CA');

insert into szk_subject


(sub_code, sub_name, class_hours, department)
values('204','CONM(Maths)', '11:00am-12:00am', 'CA');

insert into szk_subject


(sub_code, sub_name, class_hours, department)
values('205','Accounting', '12:00pm-1:00pm', 'CA');

insert into szk_instructor


(instructor_id, name)
values ('I-01', 'Ms Swati Joshi');

insert into szk_instructor


(instructor_id, name)
values ('I-02', 'Mr.Surendra Namdeo');

insert into szk_instructor


(instructor_id, name)
values ('I-03', 'Mr.O.P.Sharma');

insert into szk_instructor


(instructor_id, name)
values ('I-04', 'MR.T.K.Bhatacharya');

insert into szk_instructor


(instructor_id, name)
values ('I-05', 'Ms Shweta Mam');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-A','201','II','1998','I-01');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-A','202','II','1998','I-02');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-A','203','II','1998','I-03');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-A','204','II','1998','I-04');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-A','205','II','1998','I-05');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-B','201','II','1999','I-01');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-B','202','II','1999','I-02');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-B','203','II','1999','I-03');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-B','204','II','1999','I-04');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-B','205','II','1999','I-05');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-C','201','II','2000','I-01');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-C','202','II','2000','I-02');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-C','203','II','2000','I-03');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-C','204','II','2000','I-04');

insert into szk_section


(secidentifer, sub_code, semester, year, instructor_id)
values('Sec-C','205','II','2000','I-05');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051058','Sec-C','A');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051040','Sec-C','A');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051043','Sec-B','C');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051042','Sec-B','A');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051052','Sec-A','B');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051016','Sec-A','A');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051005','Sec-A','B');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051003','Sec-B','B');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051032','Sec-B','A');

insert into szk_grade_report


(roll_no, secidentifier, grade)
values ('0112CA051028','Sec-C','B');
primary key:-

alter table szk_student


add constrain pk_stud primary key (roll_no);

alter table szk_subject


add constrain pk_sub primary key (sub_code);

alter table szk_instructor


add constrain pk_inst primary key (instructor_id);

alter table szk_grade_report


add constraint pk_grd primary key (grade);

alter table szk_section


add constraint pk_sec primary key (secidentifier);

foreignkey:-

alter table szk_section


add constraint fk_sec foreign key instructor_id
references szk_instructor (instructor_id));

alter table szk_section


add constraint fk_sec1 foreign key sub_code
references szk_subject (sub_code));

alter table szk_grade_report


add constraint fk_gr foreign key roll_no
references szk_student (roll_no));

alter table szk_grade_report


add constraint fk_gr1 foreign key secidentifier
references szk_section (secidentifer));

drop constraint:-

alter table szk_section


drop constraint fk_sec;

alter table szk_section


drop constraint fk_sec1;

alter table szk_grade_report


drop constraint fk_gr;

alter table szk_grade_report


drop constraint fk_gr1;

drop table:-
drop table szk_student;

drop table szk_subject;

drop table szk_instructor;

drop table szk_section;

drop table szk_grade_report;

queries:-
Q.1 Retrieve the names of all senior students of (III year(V sem)) of branch ‘CA’.
select name from szk_student
where year='III';

Q.2 Retrieve the names of all subject taught by Prof. King in 1998 & 1999.
select distinct su.sub_name from
szk_subject su, szk_instructor i, szk_section se
where ((se.year='1998' or se.year='1999') and i.name='Prof. King')
and su.sub_code=se.sub_code and i.instructor_id=se.instructor_id;

Q.3 For each section taught by prof. King, retrieve the course number, semester, year.
select distinct se.secidentifer, se.sub_code, se.year, se.semester from
szk_subject su, szk_section se, szk_instructor i
where i.name='Prof. King'
and su.sub_code=se.sub_code and i.instructor_id=se.instructor_id;

Q.4 For each section find number of students who took the section.
select secidentifier, count(roll_no)”No Of Students” from szk_grade_report
group by secidentifier;

Q.5 Retieve the name and transcript of each senior student, branch in ‘CA’. A transcript
includes subject name, subject code, semester, year and grade for each subject
completed by the student.
select distinct s.name, su.sub_name, su.sub_code, s.year, se.semester,
se.year, gr.grade
from szk_student s, szk_subject su, szk_section se, szk_grade_report gr
where (s.year='II' or s.year='III') and s.roll_no=gr.roll_no and
se.secidentifer=gr.secidentifier and su.sub_code=se.sub_code
order by su.sub_code;

Q.6 Retrieve the name of student, department in which student have grade A in their
subject.
select name, branch from szk_student
where (roll_no in (select roll_no from szk_grade_report
where grade='A'));

Q.7 Create a view that has the roll no, student name and their grade.
create or replace view student_detail
as(select s.roll_no, s.name, g.grade from
szk_student s, szk_grade_report g
where (s.roll_no=g.roll_no));

select * from student_detail;

Q.8 Create a view that has name of prof. who taught in 1999 and 2000.
create or replace view prof_98_99
as(select i.name, se.year from szk_instructor i, szk_section se
where (se.year='1998' or se.year='1999') and
i.instructor_id=se.instructor_id);

select * from prof_98_99;

Q.9 Retrieve the name of student, department in which student not have grade A in their
subject.
select s.name, s.branch, g.grade from szk_student s, szk_grade_report g
where not g.grade='A' and s.roll_no=g.roll_no
order by g.grade;

Q.10 Retreive name and Id of all the Instructors.

select * from szk_instructor;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy