Sei sulla pagina 1di 98

Roll No:240 Name: KIRAN SHINDE Assignment No 1: Consider the following Entities & Relationships Room(Rno, roomtype, Rate)

Guest(Gno,gname,no_of_days) Room and Guest are related with one to one relationship. Constraint: Primary Key No_of_days should be > 0 Create a RDB in 3NF & write queries in Oracle 8i for following. Find the type of room number 101 Find the name of guest who have allocated room more than three days Display the room information having maximum rate. List room wise guest name

SQL> create table room240 2 (r_no varchar2(20) primary key, 3 r_type varchar2(20), 4 rate number(9,2)); Table created. SQL> create table guest240 2 (g_no varchar2(20) primary key,

3 4 5 6

g_name varchar2(20), no_of_days number(7), r_no varchar2(20) references room240(r_no), CHECK (no_of_days>0));

Table created. SQL> desc room240; Name Null? ---------------------------------------- -------------R_NO NOT NULL R_TYPE RATE SQL> desc guest240 Name Null? ----------------------------------------- -------------G_NO NOT NULL G_NAME NO_OF_DAYS R_NO SQL> insert into room240 2 values('&r_no','&r_type','&rate'); Enter value for r_no: 1 Enter value for r_type: deluxe Enter value for rate: 350.50 old 2: ('&r_no','&r_type','&rate') new 2: ('1','deluxe','350.50') 1 row created. SQL> / Enter value for r_no: 101 Enter value for r_type: super deluxe Enter value for rate: 550 old 2: ('&r_no','&r_type','&rate') new 2: ('101','super deluxe','550') 1 row created. SQL> / Enter value for r_no: 102 Enter value for r_type: non A/C Enter value for rate: 250 old 2: ('&r_no','&r_type','&rate') new 2: ('102','non A/C','250') 1 row created. SQL> / Enter value for r_no: 103 Type ---------------------------VARCHAR2(20) VARCHAR2(20) NUMBER(9,2) Type ---------------------------VARCHAR2(20) VARCHAR2(20) NUMBER(7) VARCHAR2(20)

Enter value for r_type: luxury Enter value for rate: 500 old 2: ('&r_no','&r_type','&rate') new 2: ('103','luxury','500') 1 row created. SQL> / Enter value for r_no: 104 Enter value for r_type: deluxe Enter value for rate: 300 old 2: ('&r_no','&r_type','&rate') new 2: ('104','deluxe','300') 1 row created. SQL> select * from room240; R_NO R_TYPE RATE -------------------- -------------------- ---------1 deluxe 350.5 101 super deluxe 550 102 non A/C 250 103 luxury 500 104 deluxe 300 SQL> insert into guest240 values 2 ('&g_no','&g_name','&no_of_days','&r_no'); Enter value for g_no: 10 Enter value for g_name: sameer Enter value for no_of_days: 3 Enter value for r_no: 1 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('10','sameer','3','1') 1 row created. SQL> / Enter value for g_no: 11 Enter value for g_name: kiran Enter value for no_of_days: 4 Enter value for r_no: 1 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('11','kiran','4','1') 1 row created. SQL> / Enter value for g_no: 12 Enter value for g_name: manoj Enter value for no_of_days: 2 Enter value for r_no: 240

old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('12','manoj','2','101') 1 row created. SQL> / Enter value for g_no: 13 Enter value for g_name: kunal Enter value for no_of_days: 4 Enter value for r_no: 101 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('13','kunal','4','101') 1 row created. SQL> / Enter value for g_no: 14 Enter value for g_name: pratik Enter value for no_of_days: 3 Enter value for r_no: 102 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('14','pratik','3','102') 1 row created. SQL> / Enter value for g_no: 15 Enter value for g_name: vighnesh Enter value for no_of_days: 4 Enter value for r_no: 102 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('15','vighnesh','4','102') 1 row created. SQL> / Enter value for g_no: 16 Enter value for g_name: sunny Enter value for no_of_days: 2 Enter value for r_no: 103 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('16','sunny','2','103') 1 row created. SQL> / Enter value for g_no: 17 Enter value for g_name: siddharth Enter value for no_of_days: 5 Enter value for r_no: 103 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('17','siddharth','5','103')

1 row created. SQL> / Enter value for g_no: 19 Enter value for g_name: ajinkya Enter value for no_of_days: 4 Enter value for r_no: 104 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('19','ajinkya','4','104') 1 row created. SQL> / Enter value for g_no: 18 Enter value for g_name: satish Enter value for no_of_days: 3 Enter value for r_no: 104 old 2: ('&g_no','&g_name','&no_of_days','&r_no') new 2: ('18','satish','3','104') 1 row created. SQL> select * from guest156; G_NO G_NAME NO_OF_DAYS -------------------- -------------------- -----------------10 sameer 3 11 kiran 4 12 manoj 2 13 kunal 4 14 pratik 3 15 vighnesh 4 16 sunny 2 17 siddharth 5 19 ajinkya 4 18 satish 3 10 rows selected. Q No 1: Find the type of room number 101 SQL> select r_no,r_type from room156 2 where r_no='101'; R_NO R_TYPE -------------------- -------------------101 super deluxe Q No 2: Find the name of guest who have allocated room more than three days SQL> select g_name,no_of_days from guest156 R_NO --------------1 1 101 101 102 102 103 103 104 104

2 where no_of_days>3; G_NAME NO_OF_DAYS -------------------- ------------------kiran 4 kunal 4 vighnesh 4 siddharth 5 ajinkya 4 Q No 3: Display the room information having maximum rate. SQL> select * from room156 where rate=(select max(rate) from room156); R_NO R_TYPE RATE ------------------- --------------------------- ---------101 super deluxe 550 Q No 4: List room wise guest name SQL> select g_name,r_type from guest156,room156 2 where room156.r_no=guest156.r_no 3 ORDER BY r_type; G_NAME R_TYPE -------------------- -------------------sameer deluxe kiran deluxe ajinkya deluxe satish deluxe sunny luxury siddharth luxury pratik non A/C vighnesh non A/C manoj super deluxe kunal super deluxe 10 rows selected.

Roll No:156 Name: Kiran Shinde Assignment No 2: Consider the following Entities & Relationships Patient (pno, pname, addr) Bed(bno, roomno, description); Relationship between Patient and Bed is one to one Constraints: Primary key. Create a RDB in 3NF & write queries in Oracle 8i for following. Find the name of patients of bed number 103. Count the number of bed in room number 3 Find bed number and room number of patient Mr. Sharma List bed wise patient name along with room number

SQL> create table bed156 2 (b_no varchar2(20) primary key, 3 room_no varchar2(20), 4 description varchar2(20)); Table created.

SQL> create table patient156 2 (p_no varchar2(20) primary key, 3 p_name varchar2(20), 4 addr varchar2(20), 5 b_no varchar2(20) references bed156(b_no)); Table created. SQL> desc bed156 Name Null? ----------------------------------------- -------------B_NO NOT NULL ROOM_NO DESCRIPTION SQL> insert into bed156 values 2 ('&b_no','&room_no','&description'); Enter value for b_no: 1 Enter value for room_no: 100 Enter value for description: daily 3 times old 2: ('&b_no','&room_no','&description') new 2: ('1','100','daily 3 times') 1 row created. SQL> / Enter value for b_no: 2 Enter value for room_no: 101 Enter value for description: daily 2 times old 2: ('&b_no','&room_no','&description') new 2: ('2','101','daily 2 times') 1 row created. SQL> / Enter value for b_no: 3 Enter value for room_no: 102 Enter value for description: daily 2 times old 2: ('&b_no','&room_no','&description') new 2: ('3','102','daily 2 times') 1 row created. SQL> / Enter value for b_no: 103 Enter value for room_no: 5 Enter value for description: air pump old 2: ('&b_no','&room_no','&description') new 2: ('103','5','air pump') 1 row created. Type ---------------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> insert into bed156 values 2 ('&b_no','&room_no','&description'); Enter value for b_no: 105 Enter value for room_no: 3 Enter value for description: daily four times old 2: ('&b_no','&room_no','&description') new 2: ('105','3','daily four times') 1 row created. SQL> / Enter value for b_no: 106 Enter value for room_no: 3 Enter value for description: daily 3 times old 2: ('&b_no','&room_no','&description') new 2: ('106','3','daily 3 times') 1 row created. SQL> / Enter value for b_no: 107 Enter value for room_no: 3 Enter value for description: daily 2 times old 2: ('&b_no','&room_no','&description') new 2: ('107','3','daily 2 times') 1 row created. SQL> select * from bed156; B_NO ROOM_NO DESCRIPTION -------------------- -------------------- -------------------1 100 daily 3 times 2 101 daily2 times 3 102 daily 2 times 103 5 air pump 105 3 daily four times 106 3 daily 3 times 107 3 daily 2 times 7 rows selected. SQL> desc patient156 Name Null? ----------------------------------------- -------------P_NO NOT NULL P_NAME ADDR B_NO SQL> insert into patient156 values 2 ('&p_no','&p_name','&addr','&b_no'); Type ----------------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

Enter value for p_no: 1 Enter value for p_name: vishal Enter value for addr: pune Enter value for b_no: 1 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('1','vishal','pune','1') 1 row created. SQL> / Enter value for p_no: 2 Enter value for p_name: kunal Enter value for addr: kothrud Enter value for b_no: 2 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('2','kunal','kothrud','2') 1 row created. SQL> / Enter value for p_no: 3 Enter value for p_name: pratik Enter value for addr: pune Enter value for b_no: 3 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('3','pratik','pune','3') 1 row created. SQL> / Enter value for p_no: 4 Enter value for p_name: sushant Enter value for addr: nasik Enter value for b_no: 103 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('4','sushant','nasik','103') 1 row created. SQL> / Enter value for p_no: 5 Enter value for p_name: naresh Enter value for addr: mumbai Enter value for b_no: 105 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('5','naresh','mumbai','105') 1 row created. SQL> / Enter value for p_no: 6 Enter value for p_name: jayesh

Enter value for addr: hinjawadi Enter value for b_no: 106 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('6','jayesh','hinjawadi','106') 1 row created. SQL> / Enter value for p_no: 7 Enter value for p_name: mahesh Enter value for addr: pune Enter value for b_no: 107 old 2: ('&p_no','&p_name','&addr','&b_no') new 2: ('7','mahesh','pune','107') 1 row created. SQL> insert into patient156 values 2 ('10','mr.sharma','pune','105'); 1 row created. SQL> select * from patient156; P_NO P_NAME ADDR B_NO -------------------- ----------------- --------------- ------------------1 vishal pune 1 2 kunal kothrud 2 3 pratik pune 3 4 sushant nasik 103 5 naresh mumbai 105 6 jayesh hinjawadi 106 7 mahesh pune 107 10 mr.sharma pune 105 7 rows selected. Q No 1: Find the name of patients of bed number 103. SQL> select bed156.b_no,p_name from bed156,patient156 2 where bed156.b_no=patient156.b_no 3 and bed156.b_no='103'; B_NO P_NAME -------------------- -------------------103 sushant Q No 2: Count the number of bed in room number 3 SQL> select count(b_no) from bed156 2 where room_no='3';

COUNT(B_NO) -------------------3 Q No 3: Find bed number and room number of patient Mr. Sharma SQL> select bed156.b_no,bed156.room_no,p_name from bed156,patient156 2 where bed156.b_no=patient156.b_no 3 and p_name like 'mr.sharma'; B_NO ROOM_NO P_NAME -------------------- --------------- -------------------105 3 mr.sharma Q No 4: List bed wise patient name along with room number SQL> select bed156.b_no,p_name,room_no from patient156,bed156 2 where bed156.b_no=patient156.b_no 3 GROUP BY bed156.b_no,p_name,room_no; B_NO P_NAME ROOM_NO -------------------- -------------------- -------------------1 vishal 100 2 kunal 101 3 pratik 102 103 sushant 5 105 naresh 3 105 mr.sharma 3 106 jayesh 3 107 mahesh 3 8 rows selected.

Roll No:156 Name: Kiran Shinde Assignment No 3: Consider the following entities & relationships Plant ( Plant_Code, Plant_Name,Plant_Cost, Plant_Type) Nutrients (Ncode, N_Name) Plant and Nutrients are related with one to many relationship Constraints : Primary Key, Quantity should be > 0 Plant Type Constraint: F- Flowering and NF Non-flowering

Create a RDB in 3NF & write queries in Oracle 8i for following. Count the number of plants for each plant type List all nutrients whose name start with U List all the plants to whom nutrients Urea is given Display plant wise nutrients given

SQL> create table plant156 2 (p_code varchar2(20) primary key, 3 p_name varchar2(20), 4 p_cost number(9,2), 5 p_type varchar2(2), 6 CHECK (p_type in('F','NF'))); Table created.

SQL> create table nutrients156 2 (n_code varchar2(20) primary key, 3 n_name varchar2(20), 4 p_code varchar2(20) references plant156(p_code)); Table created. SQL> desc plant156 Name Null? Type ----------------------------------------- --------------- ---------------------------P_CODE NOT NULL VARCHAR2(20) P_NAME VARCHAR2(20) P_COST NUMBER(9,2) P_TYPE VARCHAR2(2) SQL> insert into plant156 values 2 ('1','tulsi','20','F'); 1 row created. SQL> insert into plant156 values 2 ('&p_code','&p_name','&p_cost','&p_type'); Enter value for p_code: 2 Enter value for p_name: banana Enter value for p_cost: 15 Enter value for p_type: NF old 2: ('&p_code','&p_name','&p_cost','&p_type') new 2: ('2','banana','15','NF') 1 row created. SQL> / Enter value for p_code: 3 Enter value for p_name: nim Enter value for p_cost: 25 Enter value for p_type: F old 2: ('&p_code','&p_name','&p_cost','&p_type') new 2: ('3','nim','25','F') 1 row created. SQL> / Enter value for p_code: 4 Enter value for p_name: apple Enter value for p_cost: 40 Enter value for p_type: F old 2: ('&p_code','&p_name','&p_cost','&p_type') new 2: ('4','apple','40','F') 1 row created.

SQL> / Enter value for p_code: 5 Enter value for p_name: mogara Enter value for p_cost: 15 Enter value for p_type: NF old 2: ('&p_code','&p_name','&p_cost','&p_type') new 2: ('5','mogara','15','NF') 1 row created. SQL> select * from plant156; P_CODE P_NAME P_COST -------------------- -------------------- ---------1 tulsi 20 2 banana 15 3 nim 25 4 apple 40 5 mogara 15 P_TYPE -----------F NF F F NF

SQL> desc nutrients156 Name Null? Type ----------------------------------------- -------------- ---------------------------N_CODE NOT NULL VARCHAR2(20) N_NAME VARCHAR2(20) P_CODE VARCHAR2(20) SQL> insert into nutrients156 values 2 ('10','vitamin','1'); 1 row created. SQL> insert into nutrients156 values 2 ('&n_code','&n_name','&p_code'); Enter value for n_code: 11 Enter value for n_name: protin Enter value for p_code: 2 old 2: ('&n_code','&n_name','&p_code') new 2: ('11','protin','2') 1 row created. SQL> / Enter value for n_code: 12 Enter value for n_name: calcium Enter value for p_code: 3 old 2: ('&n_code','&n_name','&p_code') new 2: ('12','calcium','3') 1 row created. SQL> /

Enter value for n_code: 13 Enter value for n_name: oxigen Enter value for p_code: 4 old 2: ('&n_code','&n_name','&p_code') new 2: ('13','oxigen','4') 1 row created. SQL> / Enter value for n_code: 14 Enter value for n_name: protin Enter value for p_code: 5 old 2: ('&n_code','&n_name','&p_code') new 2: ('14','protin','5') 1 row created. SQL> / Enter value for n_code: 15 Enter value for n_name: urea Enter value for p_code: 1 old 2: ('&n_code','&n_name','&p_code') new 2: ('15','urea','1') 1 row created. SQL> / Enter value for n_code: 16 Enter value for n_name: urea Enter value for p_code: 2 old 2: ('&n_code','&n_name','&p_code') new 2: ('16','urea','2') 1 row created. SQL> select * from nutrients156; N_CODE N_NAME P_CODE -------------------- -------------------- -------------------10 vitamin 1 11 protin 2 12 calcium 3 13 oxigen 4 14 protin 5 15 urea 1 16 urea 2 7 rows selected.

Q No 1: Count the number of plants for each plant type SQL> select count(*),p_type from plant156 2 GROUP BY p_type; COUNT(*) ---------3 2 P_TYPE --------------F NF

Q No 2: List all nutrients whose name start with U SQL> select n_name from nutrients156 2 where n_name like 'u%'; N_NAME -------------------urea urea Q No 3: List all the plants to whom nutrients Urea is given SQL> select p_name,n_name from plant156,nutrients156 2 where plant156.p_code=nutrients156.p_code 3 and n_name like 'urea'; P_NAME N_NAME -------------------- -------------------tulsi urea banana urea Q No 4: Display plant wise nutrients given SQL> select n_name,p_name from plant156,nutrients156 2 where plant156.p_code=nutrients156.p_code 3 GROUP BY p_name,n_name 4 ; N_NAME P_NAME -------------------- -------------------calcium nim oxigen apple urea tulsi vitamin tulsi urea banana protin banana protin mogara 7 rows selected.

Roll No:156 Name: Kiran Shinde Assignment No 4: Consider the following entities & relationships Department( dno,dname,HOD,location) Project (pno, pname, status) Department and Project are related with one to many relationships Constraints : Primary Key, Project Status Constraints: C completed, P-Progressive, I-Incomplete Create a RDB in 3NF & write queries in Oracle 8i for following. Find HOD of Computer Department located in Pune. List all projects of mathematics department which are Incomplete Display the Project details of Computer Department List department wise project along with status

SQL> create table dep156 2 (d_no varchar2(20) primary key, 3 d_name varchar2(20), 4 HOD varchar2(20), 5 location varchar2(20)); Table created.

SQL> create table pro156 2 (p_no varchar2(20) primary key, 3 p_name varchar2(20), 4 status char(1), 5 d_no varchar2(20) references dep156(d_no), 6 CHECK (status in('C','I','P'))); Table created. SQL> desc dep156; Name Null? ----------------------------------------- --------------D_NO NOT NULL D_NAME HOD LOCATION Type ---------------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> insert into dep156 values 2 ('&d_no','&d_name','&HOD','&location'); Enter value for d_no: 1 Enter value for d_name: sales Enter value for hod: vinaya mam Enter value for location: pune old 2: ('&d_no','&d_name','&HOD','&location') new 2: ('1','sales','vinaya mam','pune') 1 row created. SQL> / Enter value for d_no: 2 Enter value for d_name: purchases Enter value for hod: renuka mam Enter value for location: mumbai old 2: ('&d_no','&d_name','&HOD','&location') new 2: ('2','purchases','renuka mam','mumbai') 1 row created. SQL> / Enter value for d_no: 3 Enter value for d_name: computer Enter value for hod: sadanand sir Enter value for location: baramati old 2: ('&d_no','&d_name','&HOD','&location') new 2: ('3','computer','sadanand sir','baramati') 1 row created. SQL> / Enter value for d_no: 4 Enter value for d_name: bca

Enter value for hod: bapat sir Enter value for location: chinchwad old 2: ('&d_no','&d_name','&HOD','&location') new 2: ('4','bca','bapat sir','chinchwad') 1 row created. SQL> / Enter value for d_no: 5 Enter value for d_name: mathematics Enter value for hod: das sir Enter value for location: pune old 2: ('&d_no','&d_name','&HOD','&location') new 2: ('5','mathematics','das sir','pune') 1 row created. SQL> select * from dep156; D_NO D_NAME -------------------- -------------------1 sales 2 purchases 3 computer 4 bca 5 mathematics HOD LOCATION -------------------- -------------------vinaya mam pune renuka mam mumbai sadanand sir baramati bapat sir chinchwad das sir pune Null? Type --------------------- --------------------NOT NULL VARCHAR2(20) VARCHAR2(20) CHAR(1) VARCHAR2(20)

SQL> desc pro156; Name --------------------------------------------------P_NO P_NAME STATUS D_NO

SQL> insert into pro156 values 2 ('&p_no','&p_name','&status','&d_no'); Enter value for p_no: hpcl Enter value for p_name: hpcl Enter value for status: C Enter value for d_no: 1 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('hpcl','hpcl','C','1') 1 row created. SQL> / Enter value for p_no: 2 Enter value for p_name: java Enter value for status: I Enter value for d_no: 1 old 2: ('&p_no','&p_name','&status','&d_no')

new 2: ('2','java','I','1') 1 row created. SQL> / Enter value for p_no: 3 Enter value for p_name: CPP Enter value for status: I Enter value for d_no: 2 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('3','CPP','I','2') 1 row created. SQL> / Enter value for p_no: 4 Enter value for p_name: VB Enter value for status: C Enter value for d_no: 2 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('4','VB','C','2') 1 row created. SQL> / Enter value for p_no: 5 Enter value for p_name: ob Enter value for status: C Enter value for d_no: 3 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('5','ob','C','3') 1 row created. SQL> / Enter value for p_no: 6 Enter value for p_name: vb.net Enter value for status: I Enter value for d_no: 4 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('6','vb.net','I','4') 1 row created. SQL> / Enter value for p_no: 7 Enter value for p_name: oc Enter value for status: P Enter value for d_no: 5 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('7','oc','P','5')

1 row created. SQL> / Enter value for p_no: 8 Enter value for p_name: MP Enter value for status: P Enter value for d_no: 5 old 2: ('&p_no','&p_name','&status','&d_no') new 2: ('8','MP','P','5') 1 row created. SQL> select * from pro156; P_NO ------------1 2 3 4 5 6 7 8 P_NAME STATUS D_NO ------------ ------------- ---------hpcl C 1 java I 1 CPP I 2 VB C 2 ob C 3 vb.net I 4 oc P 5 MP P 5

8 rows selected. Q No 1: Find HOD of Computer Department located in Pune. SQL> select HOD,d_name from dep156 2 where d_name='computer'; HOD D_NAME -------------------- -------------------sadanand sir computer Q No 2: List all projects of mathematics department which are Incomplete SQL> select p_name,status from dep156,pro156 2 where pro156.d_no=dep156.d_no 3 and status='P'; P_NAME S --------------- ---oc P MP P Q No 3: Display the Project details of Computer Department SQL> select d_name,pro156.* from dep156,pro156 2 where pro156.d_no=dep156.d_no 3 and d_name like 'computer';

D_NAME P_NO P_NAME S -------------------- -------------------- -------------------computer 5 ob C

D_NO ----------------3

Q No 4: List department wise project along with status SQL> select d_name,status,p_name from dep156,pro156 2 where pro156.d_no=dep156.d_no 3 GROUP BY d_name,status,p_name; D_NAME S P_NAME -------------------- ---- -----------------bca I vb.net sales C hpcl sales I java computer C ob purchases C VB purchases I CPP mathematics P MP mathematics P oc 8 rows selected.

Roll No:156 Name: Kiran Shinde Assignment No 5: Consider the following Entities & Relationships Company(cid,cname,cproduct,state) Branches(bno, city) Company and Branches are related with one to many relationships Constraint: Primary Key, Customer Name should not be null Create a RDB in 3NF & write queries in Oracle 8i for following. List the product names of company MicroTech List all the companies of product keyboard List all the branches along with city of company Lenovo Count the number of branches of company Compaq

SQL> create table company156 2 (c_id varchar2(20) primary key, 3 c_name varchar2(20) NOT NULL, 4 c_product varchar2(20), 5 state varchar2(20));

Table created. SQL> create table branches156 2 (b_no varchar2(20) primary key, 3 city varchar2(20), 4 c_id varchar2(20) references company156(c_id)); Table created. SQL> desc company156; Name Null? ----------------------------------------------------- -------------C_ID NOT NULL C_NAME NOT NULL C_PRODUCT STATE SQL> insert into company156 values 2 ('&c_id','&c_name','&c_product','&state'); Enter value for c_id: 1 Enter value for c_name: micro tech Enter value for c_product: keyboard Enter value for state: maharashtra old 2: ('&c_id','&c_name','&c_product','&state') new 2: ('1','micro tech','keyboard','maharashtra') 1 row created. SQL> / Enter value for c_id: 2 Enter value for c_name: compaq Enter value for c_product: mouse Enter value for state: kerala old 2: ('&c_id','&c_name','&c_product','&state') new 2: ('2','compaq','mouse','kerala') 1 row created. SQL> / Enter value for c_id: 3 Enter value for c_name: lenovo Enter value for c_product: mobile Enter value for state: maharashtra old 2: ('&c_id','&c_name','&c_product','&state') new 2: ('3','lenovo','mobile','maharashtra') 1 row created. SQL> / Enter value for c_id: 4 Enter value for c_name: amdocs Enter value for c_product: mother board Type -----------------------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

Enter value for state: karnataka old 2: ('&c_id','&c_name','&c_product','&state') new 2: ('4','amdocs','mother board','karnataka') 1 row created. SQL> / Enter value for c_id: 5 Enter value for c_name: cognizent Enter value for c_product: cpu Enter value for state: rajasthan old 2: ('&c_id','&c_name','&c_product','&state') new 2: ('5','cognizent','cpu','rajasthan') 1 row created. SQL> select * from company156; C_ID C_NAME C_PRODUCT -------------------- -------------------- -------------------1 micro tech keyboard 2 compaq mouse 3 lenovo mobile 4 amdocs mother board 5 cognizent cpu STATE --------------------maharashtra kerala maharashtra karnataka rajasthan Type -----------------------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> desc branches156 Name Null? ----------------------------------------------------- -------------B_NO NOT NULL CITY C_ID SQL> insert into branches156 values 2 ('&b_no','&city','&c_id'); Enter value for b_no: 10 Enter value for city: pune Enter value for c_id: 1 old 2: ('&b_no','&city','&c_id') new 2: ('10','pune','1') 1 row created. SQL> / Enter value for b_no: 11 Enter value for city: mumbai Enter value for c_id: 1 old 2: ('&b_no','&city','&c_id') new 2: ('11','mumbai','1') 1 row created.

SQL> / Enter value for b_no: 12 Enter value for city: desham Enter value for c_id: 3 old 2: ('&b_no','&city','&c_id') new 2: ('12','desham','3') 1 row created. SQL> / Enter value for b_no: 13 Enter value for city: hubli Enter value for c_id: 2 old 2: ('&b_no','&city','&c_id') new 2: ('13','hubli','2') 1 row created. SQL> / Enter value for b_no: 14 Enter value for city: chinchwad Enter value for c_id: 4 old 2: ('&b_no','&city','&c_id') new 2: ('14','chinchwad','4') 1 row created. SQL> / Enter value for b_no: 15 Enter value for city: madhuban Enter value for c_id: 5 old 2: ('&b_no','&city','&c_id') new 2: ('15','madhuban','5') 1 row created. SQL> select * from branches156; B_NO CITY C_ID -------------------- -------------------- -----------10 pune 1 11 mumbai 1 12 desham 3 13 hubli 2 14 chinchwad 4 15 madhuban 5 6 rows selected.

Q No 1: List the product names of company MicroTech SQL> select c_product,c_name from company156 2 where c_name like 'micro tech'; C_PRODUCT C_NAME -------------------- -------------------keyboard micro tech Q No 2: List all the companies of product keyboard SQL> select c_name,c_product from company156 2 where c_product like 'keyboard'; C_NAME C_PRODUCT -------------------- -------------------micro tech keyboard Q No 3: List all the branches along with city of company Lenovo SQL> select b_no,city,c_name from branches156,company156 2 where company156.c_id=branches156.c_id 3 and c_name like 'lenovo'; B_NO CITY C_NAME -------------------- -------------------- -------------------12 desham lenovo Q No 4: Count the number of branches of company Compaq SQL> select count(b_no) from company156,branches156 2 where company156.c_id=branches156.c_id 3 and c_name like 'compaq'; COUNT(B_NO) ----------1

Roll No:156 Name: Kiran Shinde Assignment No 6: Consider the following Entities & Relationships Person (pno,pname,birthdate,income) Area (Ano,aname,atype); Relationship between Person and area is many to one Constraints : Primary key, Area type may be either rural or urban. Create a RDB in 3NF & write queries in Oracle 8i for following. List the name of all person living in urban area List details of all persons whose name start with alphabet M Display the details of person having maximum Income Count the number of persons from each type of area.

SQL> create table area156 2 (a_no varchar2(20) primary key, 3 a_name varchar2(20), 4 a_type char(5), 5 CHECK (a_type in('Rural','Urban')));

Table created. SQL> create table person156 2 (p_no varchar2(20) primary key, 3 p_name varchar2(20), 4 birth_date date, 5 income number(9,2), 6 a_no varchar2(20) references area156(a_no)); Table created. SQL> desc area156 Name Null? ----------------------------------------- --------------A_NO NOT NULL A_NAME A_TYPE SQL> insert into area156 values 2 ('&a_no','&a_name','&a_type'); Enter value for a_no: 1 Enter value for a_name: kothrud Enter value for a_type: Urban old 2: ('&a_no','&a_name','&a_type') new 2: ('1','kothrud','Urban') 1 row created. SQL> / Enter value for a_no: 2 Enter value for a_name: khedegaon Enter value for a_type: Rural old 2: ('&a_no','&a_name','&a_type') new 2: ('2','khedegaon','Rural') 1 row created. SQL> / Enter value for a_no: 3 Enter value for a_name: nasik Enter value for a_type: Urban old 2: ('&a_no','&a_name','&a_type') new 2: ('3','nasik','Urban') 1 row created. SQL> / Enter value for a_no: 4 Enter value for a_name: gurgaon Enter value for a_type: Rural old 2: ('&a_no','&a_name','&a_type') new 2: ('4','gurgaon','Rural') Type ---------------------------VARCHAR2(20) VARCHAR2(20) CHAR(5)

1 row created. SQL> / Enter value for a_no: 5 Enter value for a_name: mumbai Enter value for a_type: Urban old 2: ('&a_no','&a_name','&a_type') new 2: ('5','mumbai','Urban') 1 row created. SQL> select * from area156; A_NO ------------1 2 3 4 5 A_NAME A_TYPE -------------------- ----------kothrud Urban khedegaon Rural nasik Urban gurgaon Rural mumbai Urban Type ---------------------------VARCHAR2(20) VARCHAR2(20) DATE NUMBER(9,2) VARCHAR2(20)

SQL> desc person156; Name Null? ----------------------------------------- ----------------P_NO NOT NULL P_NAME BIRTH_DATE INCOME A_NO

SQL> insert into person156 values 2 ('&p_no','&p_name','&birth_date','&income','&a_no'); Enter value for p_no: 1 Enter value for p_name: rahul Enter value for birth_date: 25-jan-1990 Enter value for income: 24000 Enter value for a_no: 1 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('1','rahul','25-jan-1990','24000','1') 1 row created. SQL> / Enter value for p_no: 2 Enter value for p_name: manoj Enter value for birth_date: 14-mar-1988 Enter value for income: 25000 Enter value for a_no: 1 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('2','manoj','14-mar-1988','25000','1')

1 row created. SQL> / Enter value for p_no: 3 Enter value for p_name: kunal Enter value for birth_date: 14-jan-1986 Enter value for income: 28000 Enter value for a_no: 3 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('3','kunal','14-jan-1986','28000','3') 1 row created. SQL> / Enter value for p_no: 4 Enter value for p_name: shahid Enter value for birth_date: 14-nov-1990 Enter value for income: 28000 Enter value for a_no: 5 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('4','shahid','14-nov-1990','28000','5') 1 row created. SQL> / Enter value for p_no: 5 Enter value for p_name: vishal Enter value for birth_date: 14-feb-1989 Enter value for income: 9000 Enter value for a_no: 2 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('5','vishal','14-feb-1989','9000','2') 1 row created. SQL> / Enter value for p_no: 6 Enter value for p_name: pratik Enter value for birth_date: 14-feb-1990 Enter value for income: 16000 Enter value for a_no: 5 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('6','pratik','14-feb-1990','16000','5') 1 row created. SQL> / Enter value for p_no: 7 Enter value for p_name: sushant Enter value for birth_date: 14-dec-1989 Enter value for income: 4500 Enter value for a_no: 4

old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('7','sushant','14-dec-1989','4500','4') 1 row created. SQL> / Enter value for p_no: 8 Enter value for p_name: lalit Enter value for birth_date: 14-feb-1985 Enter value for income: 10000 Enter value for a_no: 2 old 2: ('&p_no','&p_name','&birth_date','&income','&a_no') new 2: ('8','lalit','14-feb-1985','10000','2') 1 row created. SQL> select * from person156; P_NO P_NAME BIRTH_DATE INCOME -------------- -------------------- ------------------------------1 rahul 25-JAN-90 24000 2 manoj 14-MAR-88 25000 3 kunal 14-JAN-86 28000 4 shahid 14-NOV-90 28000 5 vishal 14-FEB-89 9000 6 pratik 14-FEB-90 16000 7 sushant 14-DEC-89 4500 8 lalit 14-FEB-85 10000 8 rows selected. Q No 1: List the name of all person living in urban area SQL> select p_name,a_type from person156,area156 2 where area156.a_no=person156.a_no 3 and a_type like 'Urban'; P_NAME -----------------rahul manoj kunal shahid pratik A_TYPE ------------Urban Urban Urban Urban Urban A_NO ------1 1 3 5 2 5 4 2

Q No 2: List details of all persons whose name start with alphabet M SQL> select * from person156 2 where p_name like 'm%'; P_NO P_NAME BIRTH_DAT INCOME A_NO ---------- ----------------- -------------------- ---------- --------2 manoj 14-MAR-88 25000 1 Q NO 3: Display the details of person having maximum Income SQL> select person156.* from person156 2 where income=(select max(income) from person156); P_NO P_NAME BIRTH_DAT INCOME A_NO ------------- --------------- -------------------- ------------- -----------3 kunal 14-JAN-86 28000 3 4 shahid 14-NOV-90 28000 5 Q NO 4: Count the number of persons from each type of area. SQL> select count(p_name),a_type from person156,area156 2 where area156.a_no=person156.a_no 3 GROUP BY a_type; COUNT(P_NAME) A_TYP ------------------------------3 Rural 5 Urban

Roll No:156 Name: Kiran Shinde Assignment No 7: Consider the following Entities & Relationships Politician(pno,pname,pdesc) Party(party_code,party_name) Politician & party are related with many-to-one. Constraints : Primary key, Foreign key, Party_name Not NULL Create a RDB in 3NF & write queries in Oracle 8i for following. Display party wise politician details Display details of all politician of party BJP Count the total number of politicians for each part Count the number of politicians having political description as

SQL> create table party156 2 (party_code varchar2(20) primary key, 3 party_name varchar2(20) NOT NULL); Table created.

SQL> create table politician156 2 (p_no varchar2(20) primary key, 3 p_name varchar2(20), 4 p_desc varchar2(20), 5 party_code varchar2(20) references party156(party_code)); Table created. SQL> desc party207 Name Null? Type

----------------------------------------- ----------------- --------------------PARTY_CODE PARTY_NAME NOT NULL NOT NULL VARCHAR2(20) VARCHAR2(20)

SQL> insert into party156 values 2 ('&party_code','&party_name'); Enter value for party_code: 1 Enter value for party_name: BJP old 2: ('&party_code','&party_name') new 2: ('1','BJP')

1 row created.

SQL> / Enter value for party_code: 2 Enter value for party_name: MNS old 2: ('&party_code','&party_name') new 2: ('2','MNS')

1 row created.

SQL> / Enter value for party_code: 3 Enter value for party_name: Congress old 2: ('&party_code','&party_name') new 2: ('3','Congress')

1 row created.

SQL> select * from party156;

PARTY_CODE

PARTY_NAME

-------------------- -------------------1 2 3 BJP MNS Congress

SQL> desc politician156 Name Null? Type

----------------------------------------- -------------------- -------------------P_NO P_NAME P_DESC PARTY_CODE NOT NULL VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> insert into politician156 values 2 ('&p_no','&p_name','&p_desc','&party_code'); Enter value for p_no: 101

Enter value for p_name: mr mohan Enter value for p_desc: MH Enter value for party_code: 1 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('101','mr mohan','MH','1')

1 row created.

SQL> / Enter value for p_no: 102 Enter value for p_name: mr karan Enter value for p_desc: AP Enter value for party_code: 1 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('102','mr karan','AP','1')

1 row created.

SQL> / Enter value for p_no: 103 Enter value for p_name: mr pandey Enter value for p_desc: MH Enter value for party_code: 2 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('103','mr pandey','MH','2')

1 row created.

SQL> / Enter value for p_no: 104 Enter value for p_name: mrs kale Enter value for p_desc: MH Enter value for party_code: 2 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('104','mrs kale','MH','2')

1 row created.

SQL> / Enter value for p_no: 105 Enter value for p_name: mr janasingh Enter value for p_desc: AP Enter value for party_code: 2 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('105','mr janasingh','AP','2')

1 row created.

SQL> / Enter value for p_no: 106 Enter value for p_name: mr lalit Enter value for p_desc: Gujarat Enter value for party_code: 3 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('106','mr lalit','Gujarat','3')

1 row created.

SQL> / Enter value for p_no: 107 Enter value for p_name: mr manmohan Enter value for p_desc: MP Enter value for party_code: 3 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('107','mr manmohan','MP','3')

1 row created.

SQL> / Enter value for p_no: 108 Enter value for p_name: mr kamal Enter value for p_desc: MP Enter value for party_code: 2 old 2: ('&p_no','&p_name','&p_desc','&party_code') new 2: ('108','mr kamal','MP','2')

1 row created.

SQL> select * from politician156;

P_NO

P_NAME

P_DESC

PARTY_CODE

---------------- -------------------- -------------------- -------------------101 102 mr mohan mr karan MH AP 1 1

103 104 105 106 107 108

mr pandey mrs kale mr janasingh mr lalit mr manmohan mr kamal

MH MH AP Gujarat MP MP

2 2 2 3 3 2

8 rows selected. Q NO 1: Display Party Wise Politician Details. SQL> select party_name,party156.party_code,p_no,p_name,p_desc from politician156,party156 2 where party156.party_code=politician156.party_code 3 GROUP BY party_name,party156.party_code,p_no,p_name,p_desc; PARTY_NAME PARTY_CODE P_NO P_NAME P_DESC

-------------------- -------------------- --------------BJP BJP MNS MNS MNS MNS Congress Congress 1 1 2 2 2 2 3 3 101 102 103 104 105 108 106 107

-------------------- ---------------mr mohan mr karan mr pandey mrs kale mr janasingh mr kamal mr lalit mr manmohan MH AP MH MH AP MP Gujarat MP

8 rows selected.

Q NO 2: Display Details of all Politician of Party BJP. 1 select politician156.* from politician156,party156 where

2 politician156.party_code=party156.party_code and 3* party_name='BJP' P_NO P_NAME P_DESC PARTY_CODE -----------------1 1

---------------- -------------------- -------------101 102 mr mohan mr karan MH AP

Q NO 3: Count the total Number of Politician for each Party. select party_name,count(p_no) from party156,politician156 where politician156.party_code=party156.party_code group by party_name SQL> /

PARTY_NAME -------------------BJP Congress MNS

COUNT(P_NO) -------------------2 2 4

Q NO 4: Count the total Number of Politician having political Description AP. select count(p_no),p_desc from politician156 group by p_desc having p_desc='AP' SQL> /

COUNT(P_NO)

P_DESC

------------------- ------------------2 AP

Roll No:156 Name: Kiran Shinde Assignment No 8: Consider the following Entities and Relationships Employee (empno, empname, salary, commission, designation) Department (deptno, deptname,location) Relationship between Employee and Department is many-to-one. Constraints : Primary Key, Salary should be > 0.

Create a RDB in 3NF & write queries in Oracle 8i for following. Display average salary for every designation Update commission for every employee by 5 % for all department List details of employee who belong to Computer department and salary > 20000 Display all employees details whose designation is manager and salary > 25000

SQL> create table department156 2 (dept_no varchar2(20) primary key, 3 dept_name varchar2(20), 4 location varchar2(20)); Table created.

SQL> create table employee156 2 (emp_no varchar2(20) primary key, 3 emp_name varchar2(20), 4 salary number(9,2), 5 commission number(5,2), 6 designation varchar2(20), 7 dept_no varchar2(20) references department156(dept_no), 8 CHECK (salary>0)); Table created. SQL> desc department156; Name Null? ----------------------------------------- --------------DEPT_NO NOT NULL DEPT_NAME LOCATION SQL> insert into department156 values 2 ('&dept_no','&dept_name','&location'); Enter value for dept_no: 1 Enter value for dept_name: computer Enter value for location: pune old 2: ('&dept_no','&dept_name','&location') new 2: ('1','computer','pune') 1 row created. SQL> / Enter value for dept_no: 2 Enter value for dept_name: sales Enter value for location: mumbai old 2: ('&dept_no','&dept_name','&location') new 2: ('2','sales','mumbai') 1 row created. SQL> / Enter value for dept_no: 3 Enter value for dept_name: purchases Enter value for location: kothrud old 2: ('&dept_no','&dept_name','&location') new 2: ('3','purchases','kothrud') 1 row created. SQL> / Enter value for dept_no: 4 Enter value for dept_name: production Enter value for location: mumbai old 2: ('&dept_no','&dept_name','&location') new 2: ('4','production','mumbai') Type ---------------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

1 row created. SQL> select * from department156; DEPT_NO DEPT_NAME LOCATION -------------- -------------------- -------------------1 computer pune 2 sales mumbai 3 purchases kothrud 4 production mumbai SQL> desc employee156; Name Null? ----------------------------------------- ---------------EMP_NO NOT NULL EMP_NAME SALARY COMMISSION DESIGNATION DEPT_NO Type -------------------VARCHAR2(20) VARCHAR2(20) NUMBER(9,2) NUMBER(5,2) VARCHAR2(20) VARCHAR2(20)

SQL> insert into employee156 values 2 ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no'); Enter value for emp_no: 1 Enter value for emp_name: sagar Enter value for salary: 14000 Enter value for commission: 450 Enter value for designation: puen Enter value for dept_no: 1 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('1','sagar','14000','450','puen','1') 1 row created. SQL> / Enter value for emp_no: 2 Enter value for emp_name: kunal Enter value for salary: 26000 Enter value for commission: 950 Enter value for designation: manager Enter value for dept_no: 1 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('2','kunal','26000','950','manager','1') 1 row created. SQL> / Enter value for emp_no: 3 Enter value for emp_name: pratik Enter value for salary: 15000 Enter value for commission: 450

Enter value for designation: clarke Enter value for dept_no: 2 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('3','pratik','15000','450','clarke','2') 1 row created. SQL> / Enter value for emp_no: 4 Enter value for emp_name: mahesh Enter value for salary: 28000 Enter value for commission: 950 Enter value for designation: manager Enter value for dept_no: 2 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('4','mahesh','28000','950','manager','2') 1 row created. SQL> / Enter value for emp_no: 5 Enter value for emp_name: sushant Enter value for salary: 10000 Enter value for commission: 350 Enter value for designation: puen Enter value for dept_no: 3 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('5','sushant','10000','350','puen','3') 1 row created. SQL> / Enter value for emp_no: 6 Enter value for emp_name: raj Enter value for salary: 27000 Enter value for commission: 650 Enter value for designation: manager Enter value for dept_no: 3 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('6','raj','27000','650','manager','3') 1 row created. SQL> / Enter value for emp_no: 7 Enter value for emp_name: akashy Enter value for salary: 15000 Enter value for commission: 600 Enter value for designation: clarke Enter value for dept_no: 4 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('7','akashy','15000','600','clarke','4')

1 row created. SQL> / Enter value for emp_no: 8 Enter value for emp_name: mahesh Enter value for salary: 8000 Enter value for commission: 200 Enter value for designation: puen Enter value for dept_no: 4 old 2: ('&emp_no','&emp_name','&salary','&commission','&designation','&dept_no') new 2: ('8','mahesh','8000','200','puen','4') 1 row created. SQL> select * from employee156; EMP_NO ------------1 2 3 4 5 6 7 8 EMP_NAME SALARY COMMISSION DESIGNATION DEPT_NO -------------------- ------------- ------------------ -------------------- ------------sagar 14000 450 puen 1 kunal 26000 950 manager 1 pratik 15000 450 clarke 2 mahesh 28000 950 manager 2 sushant 10000 350 puen 3 raj 27000 650 manager 3 akashy 15000 600 clarke 4 mahesh 8000 200 puen 4

8 rows selected. Q No 1: Display average salary for every designation SQL> select avg(salary),designation from employee156 2 GROUP BY designation; AVG(SALARY) -------------------15000 27000 10666.6667 DESIGNATION -------------------clarke manager puen

Q No 2: Update commission for every employee by 5 % for all department SQL> update employee156 2 SET commission=commission+commission*0.05; 8 rows updated. SQL> select * from employee156; EMP_NO -----------1 2 3 4 5 6 7 8 EMP_NAME SALARY COMMISSION DESIGNATION DEPT_NO ------------------ ------------- ------------------ -------------------- -------------sagar 14000 472.5 puen 1 kunal 26000 997.5 manager 1 pratik 15000 472.5 clarke 2 mahes 28000 997.5 manager 2 sushant 10000 367.5 puen 3 raj 27000 682.5 manager 3 akashy 15000 630 clarke 4 mahesh 8000 210 puen 4

8 rows selected. Q No 3: List details of employee who belong to Computer department and salary > 20000 SQL> select employee156.*,dept_name from employee156,department156 2 where department156.dept_no=employee156.dept_no 3 and dept_name like 'computer' 4 and salary>20000; EMP_NO EMP_NAME SALARY COMMISSION DESIGNATION DEPT_NO DEPT_NAME -------------------- ----------------- -------------------- -------------------- -------------------- -------------------2 kunal 26000 92.63 manager 1 computer Q No 4: Display all employees details whose designation is manager and salary > 25000 SQL> select * from employee156 2 where designation like 'manager' 3 and salary>25000; EMP_NO -----------2 4 6 EMP_NAME SALARY COMMISSION DESIGNATION DEPT_NO ----------------- ------------------ ----------------- -------------------- -------------kunal 26000 92.63 manager 1 mahesh 28000 92.63 manager 2 raj 27000 63.38 manager 3

Roll No:156 Name: Kiran Shinde Assignment No 9: Consider the following Entities and Relationships Movie (mvno, mvname, releaseyear) Actor (actno, actname) Relationship between Movie and Actor is many-to-one. Constraints : Primary Key, releaseyear should be > 0.

Create a RDB in 3NF & write queries in Oracle 8i for following. Display all the movies released after year 2000. Count the number of movies in which Hrithik has acted. Display all the movie names order by released year in ascending order. Display movie names released between year 2000 to 2008.

SQL> create table act156 2 (a_no varchar2(20) primary key, 3 a_name varchar2(30)); Table created.

SQL> create table mv156 2 (m_no varchar2(20) primary key, 3 m_name varchar2(30), 4 r_year number(8), 5 a_no varchar2(20) references act156(a_no), 6 CHECK (r_year>0)); Table created. SQL> desc act156; Name Null? Type ----------------------------------------- --------------- --------------------A_NO NOT NULL VARCHAR2(20) A_NAME VARCHAR2(30) SQL> desc mv156; Name Null? ----------------------------------------- -------------M_NO NOT NULL M_NAME R_YEAR A_NO SQL> insert into act156 values 2 ('&a_no','&a_name'); Enter value for a_no: 1 Enter value for a_name: hrithik old 2: ('&a_no','&a_name') new 2: ('1','hrithik') 1 row created. SQL> / Enter value for a_no: 2 Enter value for a_name: salman old 2: ('&a_no','&a_name') new 2: ('2','salman') 1 row created. SQL> / Enter value for a_no: 3 Enter value for a_name: shahrukh old 2: ('&a_no','&a_name')

Type ---------------------VARCHAR2(20) VARCHAR2(30) NUMBER(8) VARCHAR2(20)

new 2: ('3','shahrukh') 1 row created. SQL> / Enter value for a_no: 4 Enter value for a_name: aamir old 2: ('&a_no','&a_name') new 2: ('4','aamir') 1 row created. SQL> / Enter value for a_no: 5 Enter value for a_name: shahid old 2: ('&a_no','&a_name') new 2: ('5','shahid') 1 row created. SQL> select * from act156; A_NO ----------1 2 3 4 5 A_NAME ---------------hrithik salman shahrukh aamir shahid

SQL> desc mv156; Name Null? ----------------------------------------- --------------M_NO NOT NULL M_NAME R_YEAR A_NO

Type --------------------VARCHAR2(20) VARCHAR2(30) NUMBER(8) VARCHAR2(20)

SQL> insert into mv156 values 2 ('&m_no','&m_name','&r_year','&a_no'); Enter value for m_no: 10 Enter value for m_name: dhoom2 Enter value for r_year: 2005 Enter value for a_no: 1 old 2: ('&m_no','&m_name','&r_year','&a_no')

new 2: ('10','dhoom2','2005','1') 1 row created. SQL> / Enter value for m_no: 11 Enter value for m_name: raone Enter value for r_year: 2010 Enter value for a_no: 3 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('11','raone','2010','3') 1 row created. SQL> / Enter value for m_no: 12 Enter value for m_name: bodyguard Enter value for r_year: 2009 Enter value for a_no: 2 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('12','bodyguard','2009','2') 1 row created. SQL> / Enter value for m_no: 13 Enter value for m_name: ready Enter value for r_year: 2008 Enter value for a_no: 2 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('13','ready','2008','2') 1 row created. SQL> / Enter value for m_no: 14 Enter value for m_name: dabangg Enter value for r_year: 2007 Enter value for a_no: 2 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('14','dabangg','2007','2') 1 row created. SQL> /

Enter value for m_no: 15 Enter value for m_name: vivah Enter value for r_year: 1999 Enter value for a_no: 5 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('15','vivah','1999','5') 1 row created. SQL> / Enter value for m_no: 16 Enter value for m_name: gajani Enter value for r_year: 2005 Enter value for a_no: 4 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('16','gajani','2005','4') 1 row created. SQL> / Enter value for m_no: 17 Enter value for m_name: rangila Enter value for r_year: 1997 Enter value for a_no: 4 old 2: ('&m_no','&m_name','&r_year','&a_no') new 2: ('17','rangila','1997','4') 1 row created. SQL> select * from mv156; M_NO -------------10 11 12 13 14 15 16 17 M_NAME ---------------------dhoom2 raone bodyguard ready dabangg vivah gajani rangila R_YEAR A_NO ---------------- -------2005 1 2010 3 2009 2 2008 2 2007 2 1999 5 2005 4 1997 4

8 rows selected.

Q No 1: Display all the movies released after year 2000. SQL> select * from mv156 2 where r_year>'2000'; M_NO ---------10 11 12 13 14 16 M_NAME ----------------------dhoom2 raone bodyguard ready dabangg gajani R_YEAR -----------2005 2010 2009 2008 2007 2005 A_NO ---------1 3 2 2 2 4

6 rows selected. Q No 2: Count the number of movies in which Hrithik has acted. SQL> select count(m_name) from act156,mv156 2 where act156.a_no=mv156.a_no 3 and a_name='hrithik'; COUNT(M_NAME) ------------1 Q No 3: Display all the movie names order by released year in ascending order. SQL> select m_name,r_year from mv156 2 ORDER BY r_year; M_NAME ------------------rangila vivah dhoom2 gajani dabangg ready bodyguard raone 8 rows selected. R_YEAR --------1997 1999 2005 2005 2007 2008 2009 2010

Q No 4: Display movie names released between year 2000 to 2008. SQL> select m_name,r_year from mv156 2 where r_year between 2000 and 2008; M_NAME R_YEAR ---------------------------- ---------dhoom2 2005 ready 2008 dabangg 2007 gajani 2005

Roll No:156 Name: Kiran Shinde Assignment No 10: Consider the following Entities and Relationships Employee (empno, empname, city, deptname) Project (pno, pname, status) Employee and Project are related with many to many relationships with descriptive attribute no_of_days employee worked on that project Constraints : Primary Key, Project Status Constraints: C completed, P-Progressive, I-Incomplete

Create a RDB in 3NF & write queries in Oracle 8i for following. List the names of employees working on projects having status Incomplete Display all project names and total number of employees who are working on that project. List the names of the employees who are working on project for more than 20 days. Display project wise Employee details

SQL> create table emp156 2 (emp_no varchar2(20) primary key, 3 emp_name varchar2(30), 4 city varchar2(20), 5 dept_name varchar2(20));

Table created. SQL> create table project156 2 (p_no varchar2(20) primary key, 3 p_name varchar2(20), 4 status char(1), 5 CHECK (status in('C','I','P'))); Table created. SQL> create table employee_project156 2 (emp_no varchar2(20) references emp156(emp_no), 3 p_no varchar2(20) references project156(p_no), 4 days number(10)); Table created. SQL> desc emp156; Name Null? ----------------------------------------- --------------EMP_NO NOT NULL EMP_NAME CITY DEPT_NAME SQL> desc project156; Name Null? ----------------------------------------- -------------P_NO NOT NULL P_NAME STATUS SQL> desc employee_project156; Name Null? ------------------------------------------------EMP_NO P_NO DAYS Type ---------------------VARCHAR2(20) VARCHAR2(30) VARCHAR2(20) VARCHAR2(20) Type ---------------------VARCHAR2(20) VARCHAR2(20) CHAR(1)

Type ---------------------------VARCHAR2(20) VARCHAR2(20) NUMBER(10)

SQL> insert into emp156 values 2 ('&emp_no','&emp_name','&city','&dept_name'); Enter value for emp_no: 11 Enter value for emp_name: rohan Enter value for city: pune Enter value for dept_name: computer old 2: ('&emp_no','&emp_name','&city','&dept_name') new 2: ('11','rohan','pune','computer') 1 row created. SQL> /

Enter value for emp_no: 12 Enter value for emp_name: kunal Enter value for city: mumbai Enter value for dept_name: sales old 2: ('&emp_no','&emp_name','&city','&dept_name') new 2: ('12','kunal','mumbai','sales') 1 row created. SQL> / Enter value for emp_no: 13 Enter value for emp_name: pratik Enter value for city: nasik Enter value for dept_name: purchases old 2: ('&emp_no','&emp_name','&city','&dept_name') new 2: ('13','pratik','nasik','purchases') 1 row created. SQL> / Enter value for emp_no: 14 Enter value for emp_name: satish Enter value for city: pune Enter value for dept_name: account old 2: ('&emp_no','&emp_name','&city','&dept_name') new 2: ('14','satish','pune','account') 1 row created. SQL> / Enter value for emp_no: 15 Enter value for emp_name: sushant Enter value for city: baramati Enter value for dept_name: sales old 2: ('&emp_no','&emp_name','&city','&dept_name') new 2: ('15','sushant','baramati','sales') 1 row created. SQL> select * from emp156; EMP_NO -------------11 12 13 14 15 EMP_NAME CITY DEPT_NAME ------------------------------ ---------------- ------------------rohan pune computer kunal mumbai sales pratik nasik purchases satish pune account sushant baramati sales

SQL> insert into project156 values 2 ('&p_no','&p_name','&status'); Enter value for p_no: 16 Enter value for p_name: java Enter value for status: P old 2: ('&p_no','&p_name','&status') new 2: ('16','java','P') 1 row created. SQL> / Enter value for p_no: 17 Enter value for p_name: C++ Enter value for status: C old 2: ('&p_no','&p_name','&status') new 2: ('17','C++','C') 1 row created. SQL> / Enter value for p_no: 18 Enter value for p_name: C++ Enter value for status: I old 2: ('&p_no','&p_name','&status') new 2: ('18','C++','I') 1 row created. SQL> / Enter value for p_no: 19 Enter value for p_name: Oracle Enter value for status: P old 2: ('&p_no','&p_name','&status') new 2: ('19','Oracle','P') 1 row created. SQL> / Enter value for p_no: 20 Enter value for p_name: HPCL Enter value for status: C old 2: ('&p_no','&p_name','&status') new 2: ('20','HPCL','C') 1 row created.

SQL> select * from project156; P_NO -------------16 17 18 19 20 P_NAME STATUS ----------------- -----------java P C++ C C++ I Oracle P HPCL C

SQL> desc employee_project156; Name Null? Type ----------------------------------------- --------------------EMP_NO VARCHAR2(20) P_NO VARCHAR2(20) DAYS NUMBER(10) SQL> insert into employee_project156 values 2 ('&emp_no','&p_no','&days'); Enter value for emp_no: 11 Enter value for p_no: 16 Enter value for days: 21 old 2: ('&emp_no','&p_no','&days') new 2: ('11','16','21') 1 row created. SQL> / Enter value for emp_no: 12 Enter value for p_no: 17 Enter value for days: 18 old 2: ('&emp_no','&p_no','&days') new 2: ('12','17','18') 1 row created. SQL> / Enter value for emp_no: 13 Enter value for p_no: 18 Enter value for days: 21 old 2: ('&emp_no','&p_no','&days') new 2: ('13','18','21') 1 row created. SQL> / Enter value for emp_no: 14 Enter value for p_no: 19 Enter value for days: 20 old 2: ('&emp_no','&p_no','&days') new 2: ('14','19','20')

1 row created. SQL> / Enter value for emp_no: 15 Enter value for p_no: 20 Enter value for days: 20 old 2: ('&emp_no','&p_no','&days') new 2: ('15','20','20') 1 row created. SQL> / Enter value for emp_no: 11 Enter value for p_no: 17 Enter value for days: 25 old 2: ('&emp_no','&p_no','&days') new 2: ('11','17','25') 1 row created. SQL> select * from employee_project156; EMP_NO P_NO ------------- ----------11 16 12 17 13 18 14 19 15 20 11 17 6 rows selected. Q No 1: List the names of employees working on projects having status Incomplete SQL> select emp_name,status from emp156,project156,employee_project156 2 where emp156.emp_no=employee_project156.emp_no and project156.p_no=employee_project156.p_no 3 and status='I'; EMP_NAME STATUS ------------------- ----------pratik I DAYS ---------21 18 21 20 20 25

Q No 2: Display all project names and total number of employees who are working on that project. SQL> select p_name,count(emp_name) from emp156,project156,employee_project156 2 where emp156.emp_no=employee_project156.emp_no and project156.p_no=employee_project156.p_no 3 GROUP BY p_name; P_NAME COUNT(EMP_NAME) -------------------- --------------------------C++ 3 HPCL 1 Oracle 1 java 1 Q No 3: List the names of the employees who are working on project for more than 20 days. SQL> select emp_name,days from emp156,project156,employee_project156 2 where emp156.emp_no=employee_project156.emp_no and project156.p_no=employee_project156.p_no 3 and days>20; EMP_NAME DAYS --------------------------- ---------rohan 21 pratik 21 rohan 25 Q No 4: Display project wise Employee details SQL> select emp156.*,p_name from emp156,project156,employee_project156 2 where emp156.emp_no=employee_project156.emp_no and project156.p_no=employee_project156.p_no 3 ORDER BY p_name; EMP_NO -------------12 13 11 15 14 11 EMP_NAME ---------------------kunal pratik rohan sushant satish rohan CITY DEPT_NAME -------------------------- -------------------mumbai sales nasik purchases pune computer baramati sales pune account pune computer P_NAME ------------C++ C++ C++ HPCL Oracle java

6 rows selected.

Roll No:156 Name: Kiran Shinde Assignment No 11: Consider the following Entities & Relationships Wholesaler(wno,wname,addr,city) Product(pno,pname) Wholesaler & Product are related with many-to-many relationship. Constraints : Primary key, pname should not be null Create a RDB in 3NF & write queries in Oracle 8i for following. Display wholesaler wise product details Count the number of products sold by wholesaler Dev Enterprise Display the details of wholesalers living in the Mumbai City Display the wholesaler details of product keyboard

SQL> create table product156 2 (p_no varchar2(20) primary key, 3 p_name varchar2(20) NOT NULL); Table created.

SQL> create table wholesaler156 2 (w_no varchar2(20) primary key, 3 w_name varchar2(20), 4 addr varchar2(20), 5 city varchar2(20)); Table created. SQL> create table prod_whole156 2 (p_no varchar2(20) references product156(p_no), 3 w_no varchar2(20) references wholesaler156(w_no)); Table created. SQL> insert into product156 values 2 ('&p_no','&p_name'); Enter value for p_no: 1 Enter value for p_name: keyboard old 2: ('&p_no','&p_name') new 2: ('1','keyboard') 1 row created. SQL> / Enter value for p_no: 2 Enter value for p_name: monitor old 2: ('&p_no','&p_name') new 2: ('2','monitor') 1 row created. SQL> / Enter value for p_no: 3 Enter value for p_name: mouse old 2: ('&p_no','&p_name') new 2: ('3','mouse') 1 row created. SQL> / Enter value for p_no: 4 Enter value for p_name: printer old 2: ('&p_no','&p_name') new 2: ('4','printer')

1 row created. SQL> / Enter value for p_no: 5 Enter value for p_name: scanner old 2: ('&p_no','&p_name') new 2: ('5','scanner') 1 row created. SQL> select * from product156; P_NO P_NAME -------------- -------------------1 keyboard 2 monitor 3 mouse 4 printer 5 scanner SQL> desc wholesaler156 Name Null? ----------------------------------------- --------------W_NO NOT NULL W_NAME ADDR CITY

Type --------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> insert into wholesaler156 values 2 ('&w_no','&w_name','&addr','&city'); Enter value for w_no: 101 Enter value for w_name: dev enterprizes Enter value for addr: M G road Enter value for city: pune old 2: ('&w_no','&w_name','&addr','&city') new 2: ('101','dev enterprizes','M G road','pune') 1 row created. SQL> / Enter value for w_no: 102 Enter value for w_name: kunal distributors Enter value for addr: J M road Enter value for city: pune old 2: ('&w_no','&w_name','&addr','&city')

new 2: ('102','kunal distributors','J M road','pune') 1 row created. SQL> / Enter value for w_no: 103 Enter value for w_name: sathe & co. Enter value for addr: bandra Enter value for city: mumbai old 2: ('&w_no','&w_name','&addr','&city') new 2: ('103','sathe & co.','bandra','mumbai') 1 row created. SQL> / Enter value for w_no: 104 Enter value for w_name: rakesh enterprizes Enter value for addr: ghatkoper Enter value for city: mumbai old 2: ('&w_no','&w_name','&addr','&city') new 2: ('104','rakesh enterprizes','ghatkoper','mumbai') 1 row created. SQL> / Enter value for w_no: 105 Enter value for w_name: lenor enterprizes Enter value for addr: baramati Enter value for city: pune old 2: ('&w_no','&w_name','&addr','&city') new 2: ('105','lenor enterprizes','baramati','pune') 1 row created. SQL> select * from wholesaler156; W_NO W_NAME ---------------- -------------------101 dev enterprizes 102 kunal distributors 103 sathe & co. 104 rakesh enterprizes 105 lenor enterprizes ADDR CITY --------------- ------------------M G road pune J M road pune bandra mumbai ghatkoper mumbai baramati pune

SQL> desc prod_whole156 Name Null? Type ----------------------------------------------------------------- -------- -------------------------------------------P_NO VARCHAR2(20) W_NO VARCHAR2(20) SQL> insert into prod_whole156 values 2 ('&p_no','&w_no'); Enter value for p_no: 1 Enter value for w_no: 105 old 2: ('&p_no','&w_no') new 2: ('1','105') 1 row created. SQL> / Enter value for p_no: 2 Enter value for w_no: 104 old 2: ('&p_no','&w_no') new 2: ('2','104') 1 row created. SQL> / Enter value for p_no: 3 Enter value for w_no: 103 old 2: ('&p_no','&w_no') new 2: ('3','103') 1 row created. SQL> / Enter value for p_no: 4 Enter value for w_no: 102 old 2: ('&p_no','&w_no') new 2: ('4','102') 1 row created. SQL> / Enter value for p_no: 5 Enter value for w_no: 101 old 2: ('&p_no','&w_no') new 2: ('5','101')

1 row created. SQL> / Enter value for p_no: 5 Enter value for w_no: 105 old 2: ('&p_no','&w_no') new 2: ('5','105') 1 row created. SQL> / Enter value for p_no: 4 Enter value for w_no: 104 old 2: ('&p_no','&w_no') new 2: ('4','104') 1 row created. SQL> / Enter value for p_no: 3 Enter value for w_no: 102 old 2: ('&p_no','&w_no') new 2: ('3','102') 1 row created. SQL> / Enter value for p_no: 4 Enter value for w_no: 103 old 2: ('&p_no','&w_no') new 2: ('4','103') 1 row created. SQL> / Enter value for p_no: 5 Enter value for w_no: 101 old 2: ('&p_no','&w_no') new 2: ('5','101') 1 row created.

SQL> select * from prod_whole156; P_NO W_NO -------------- -------------------1 105 2 104 3 103 4 102 5 101 5 105 4 104 3 102 4 103 5 101 10 rows selected. Q No 1: Display wholesaler wise product details SQL> select w_name,product156.p_no,p_name from wholesaler156,product156,prod_whole156 2 where product156.p_no=prod_whole156.p_no and 3 wholesaler156.w_no=prod_whole156.w_no 4 GROUP BY w_name,product156.p_no,p_name; W_NAME P_NO --------------------------------sathe & co. 3 sathe & co. 4 dev enterprizes 5 lenor enterprizes 1 lenor enterprizes 5 kunal distributors 3 kunal distributors 4 rakesh enterprizes 2 rakesh enterprizes 4 9 rows selected. P_NAME ------------------mouse printer scanner keyboard scanner mouse printer monitor printer

Q No 2: Count the number of products sold by wholesaler Dev Enterprise SQL> select count(p_name) from product156,wholesaler156,prod_whole156 2 where product156.p_no=prod_whole156.p_no and 3 wholesaler156.w_no=prod_whole156.w_no 4 and w_name like 'dev enterprizes'; COUNT(P_NAME) -------------------------2 Q No 3: Display the details of wholesalers living in the Mumbai City SQL> select * from wholesaler156 2 where city like 'mumbai'; W_NO --------------103 104 W_NAME ADDR CITY -------------------------- ----------------- -------------------sathe & co. bandra mumbai rakesh enterprizes ghatkoper Mumbai

Q No 4: Display the wholesaler details of product keyboard SQL> select wholesaler156.*,p_name from wholesaler156,product156,prod_whole156 2 where product156.p_no=prod_whole156.p_no and 3 wholesaler156.w_no=prod_whole156.w_no 4 and p_name like 'keyboard'; W_NO W_NAME ---------------- -------------------105 lenor enterprizes ADDR CITY P_NAME -------------------- -------------------- -------------------baramati pune keyboard

Roll No:156 Name: Kiran Shinde Assignment No 12: Consider the following Entities & Relationships Student (sno,sname,city,class) Subject (sub_no,sub_name) Students & Subjects are related with many-to-many with attribute marks. Constraints: Primary key constraints and sname not null. Class has to be FY, SY or TY. Create a RDB in 3NF & write queries in Oracle 8i for following. Display the city wise students details Find maximum marks scored in subject DBMS Display all the details of students who have scored marks less than 60 Display students who are studying in class SY and living in the city Nagpur

SQL> create table student156 2 (s_no varchar2(20) primary key, 3 s_name varchar2(20) NOT NULL, 4 city varchar2(20), 5 class char(2), 6 CHECK (class in('FY','SY','TY'))); Table created. SQL> create table subject156 2 (sub_no varchar2(20) primary key, 3 sub_name varchar2(20)); Table created. SQL> create table stud_subj156 2 (s_no varchar2(20) references student156(s_no), 3 sub_no varchar2(20) references subject156(sub_no), 4 marks number(8)); Table created. SQL> desc student156 Name Null? ----------------------------------------- -------------S_NO NOT NULL S_NAME NOT NULL CITY CLASS SQL> insert into student156 values 2 ('&s_no','&s_name','&city','&class'); Enter value for s_no: 1 Enter value for s_name: rohan Enter value for city: nagpur Enter value for class: SY old 2: ('&s_no','&s_name','&city','&class') new 2: ('1','rohan','nagpur','SY') 1 row created. SQL> / Enter value for s_no: 2 Enter value for s_name: kamlesh Enter value for city: nagpur Enter value for class: SY old 2: ('&s_no','&s_name','&city','&class') new 2: ('2','kamlesh','nagpur','SY') 1 row created. SQL> / Type ---------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) CHAR(2)

Enter value for s_no: 3 Enter value for s_name: pratik Enter value for city: pune Enter value for class: FY old 2: ('&s_no','&s_name','&city','&class') new 2: ('3','pratik','pune','FY') 1 row created. SQL> / Enter value for s_no: 4 Enter value for s_name: satish Enter value for city: pune Enter value for class: FY old 2: ('&s_no','&s_name','&city','&class') new 2: ('4','satish','pune','FY') 1 row created. SQL> / Enter value for s_no: 5 Enter value for s_name: kunal Enter value for city: mumbai Enter value for class: SY old 2: ('&s_no','&s_name','&city','&class') new 2: ('5','kunal','mumbai','SY') 1 row created. SQL> / Enter value for s_no: 6 Enter value for s_name: rahul Enter value for city: pune Enter value for class: TY old 2: ('&s_no','&s_name','&city','&class') new 2: ('6','rahul','pune','TY') 1 row created. SQL> / Enter value for s_no: 7 Enter value for s_name: vivek Enter value for city: mumbai Enter value for class: TY old 2: ('&s_no','&s_name','&city','&class') new 2: ('7','vivek','mumbai','TY') 1 row created.

SQL> select * from student156; S_NO S_NAME -------------- -------------------1 rohan 2 kamlesh 3 pratik 4 satish 5 kunal 6 rahul 7 vivek 7 rows selected. SQL> desc subject156; Name ----------------------------------------SUB_NO SUB_NAME SQL> insert into subject156 values 2 ('&sub_no','&sub_name'); Enter value for sub_no: 101 Enter value for sub_name: OB old 2: ('&sub_no','&sub_name') new 2: ('101','OB') 1 row created. SQL> / Enter value for sub_no: 102 Enter value for sub_name: DBMS old 2: ('&sub_no','&sub_name') new 2: ('102','DBMS') 1 row created. SQL> / Enter value for sub_no: 103 Enter value for sub_name: C old 2: ('&sub_no','&sub_name') new 2: ('103','C') 1 row created. SQL> select * from subject156; SUB_NO ----------------101 102 103 SUB_NAME ------------------OB DBMS C Null? Type --------------- ---------------------NOT NULL VARCHAR2(20) VARCHAR2(20) CITY --------nagpur nagpur pune pune mumbai pune mumbai CL ASS ------------SY SY FY FY SY TY TY

SQL> desc stud_subJ156; Name Null? Type ----------------------------------------------------------------- ---------------------S_NO VARCHAR2(20) SUB_NO VARCHAR2(20) MARKS NUMBER(8) SQL> insert into stud_subj156 values 2 ('&s_no','&sub_no','&marks'); Enter value for s_no: 1 Enter value for sub_no: 101 Enter value for marks: 55 old 2: ('&s_no','&sub_no','&marks') new 2: ('1','101','55') 1 row created. SQL> / Enter value for s_no: 2 Enter value for sub_no: 101 Enter value for marks: 58 old 2: ('&s_no','&sub_no','&marks') new 2: ('2','101','58') 1 row created. SQL> / Enter value for s_no: 3 Enter value for sub_no: 102 Enter value for marks: 85 old 2: ('&s_no','&sub_no','&marks') new 2: ('3','102','85') 1 row created. SQL> / Enter value for s_no: 4 Enter value for sub_no: 102 Enter value for marks: 56 old 2: ('&s_no','&sub_no','&marks') new 2: ('4','102','56') 1 row created. SQL> / Enter value for s_no: 3 Enter value for sub_no: 101 Enter value for marks: 82 old 2: ('&s_no','&sub_no','&marks') new 2: ('3','101','82')

1 row created. SQL> / Enter value for s_no: 4 Enter value for sub_no: 102 Enter value for marks: 78 old 2: ('&s_no','&sub_no','&marks') new 2: ('4','102','78') 1 row created. SQL> / Enter value for s_no: 5 Enter value for sub_no: 103 Enter value for marks: 55 old 2: ('&s_no','&sub_no','&marks') new 2: ('5','103','55') 1 row created. SQL> / Enter value for s_no: 6 Enter value for sub_no: 101 Enter value for marks: 68 old 2: ('&s_no','&sub_no','&marks') new 2: ('6','101','68') 1 row created. SQL> / Enter value for s_no: 7 Enter value for sub_no: 102 Enter value for marks: 45 old 2: ('&s_no','&sub_no','&marks') new 2: ('7','102','45') 1 row created. SQL> / Enter value for s_no: 3 Enter value for sub_no: 103 Enter value for marks: 82 old 2: ('&s_no','&sub_no','&marks') new 2: ('3','103','82') 1 row created.

SQL> select * from stud_subj156; S_NO SUB_NO MARKS -------------- -------------------- ---------1 101 55 2 101 58 3 102 85 4 102 56 3 101 82 4 102 78 5 103 55 6 101 68 7 102 45 3 103 82 10 rows selected. Q No 1: Display the city wise students details SQL> select s_no,s_name,city,class from student156 2 GROUP BY city,s_no,s_name,class; S_NO S_NAME CITY CLASS -------------- ----------------- ------------- --------------3 pratik pune FY 4 satish pune FY 6 rahul pune TY 5 kunal mumbai SY 7 vivek mumbai TY 1 rohan nagpur SY 2 kamlesh nagpur SY 7 rows selected. Q No 2: Find maximum marks scored in subject DBMS SQL> select max(marks) from student156,subject156,stud_subj156 2 where student156.s_no=stud_subj156.s_no and 3 subject156.sub_no=stud_subj156.sub_no 4 and sub_name like 'DBMS'; MAX(MARKS) ---------------------85

Q No 3: Display all the details of students who have scored marks less than 60 SQL> select student156.*,marks from student156,subject156,stud_subj156 2 where student156.s_no=stud_subj156.s_no and 3 subject156.sub_no=stud_subj156.sub_no 4 and marks<60; S_NO S_NAME CITY CLASS MARKS -------------- ----------------- ---------------- ----------- ------1 rohan nagpur SY 55 2 kamlesh nagpur SY 58 4 satish pune FY 56 5 kunal mumbai SY 55 7 vivek mumbai TY 45 Q No 4: Display students who are studying in class SY and living in the city Nagpur SQL> select s_name,class,city from student156 2 where class like 'SY' 3 and city like 'nagpur'; S_NAME CL CITY -------------------- ----- ----------------rohan SY nagpur kamlesh SY nagpur

Roll No:156 Name: Kiran Shinde Assignment No 13: Consider the following Entities & Relationships Item (item_no,name,quantity) Sup(no,name,addr,city,phone) Item & sup are related with many-to-many relationships with rate, discount. Constraints: Primary key and item qty > 5 and rate > 0. Create a RDB in 3NF & write queries in Oracle 8i for following. List all the details of items having quantity > 500 Increase the 5% rate of the item mouse Display the item details supplied by the supplier Mr. Patil Count the number of suppliers from each city

SQL> create table sup156 2 (no varchar2(20) primary key, 3 name varchar2(20), 4 addr varchar2(20), 5 city varchar2(20), 6 phone number(12));

Table created. SQL> create table item156 2 (item_no varchar2(20) primary key, 3 item_name varchar2(20), 4 quantity number(20), 5 CHECK (quantity>0)); Table created. SQL> create table sup_item156 2 (rate number(9,2), 3 discount number(7,2), 4 no varchar2(20) references sup207(no), 5 item_no varchar2(20) references item156(item_no), 6 CHECK (rate>0)); Table created. SQL> desc sup156; Name Null? Type ----------------------------------------- --------------- --------------------NO NOT NULL VARCHAR2(20) NAME VARCHAR2(20) ADDR VARCHAR2(20) CITY VARCHAR2(20) PHONE NUMBER(12) SQL> insert into sup156 values 2 ('&no','&name','&addr','&city','&phone'); Enter value for no: 1 Enter value for name: manish Enter value for addr: kothrud Enter value for city: pune Enter value for phone: 26356263 old 2: ('&no','&name','&addr','&city','&phone') new 2: ('1','manish','kothrud','pune','26356263') 1 row created. SQL> / Enter value for no: 2 Enter value for name: vishal Enter value for addr: bandra Enter value for city: mumbai Enter value for phone: 3225665 old 2: ('&no','&name','&addr','&city','&phone') new 2: ('2','vishal','bandra','mumbai','3225665') 1 row created. SQL> /

Enter value for no: 3 Enter value for name: kunal Enter value for addr: hinjawadi Enter value for city: pune Enter value for phone: 4556002 old 2: ('&no','&name','&addr','&city','&phone') new 2: ('3','kunal','hinjawadi','pune','4556002') 1 row created. SQL> / Enter value for no: 4 Enter value for name: sudhir Enter value for addr: ganesh nagar Enter value for city: nasik Enter value for phone: 3556541 old 2: ('&no','&name','&addr','&city','&phone') new 2: ('4','sudhir','ganesh nagar','nasik','3556541') 1 row created. SQL> / Enter value for no: 5 Enter value for name: ankit Enter value for addr: laxmi road Enter value for city: pune Enter value for phone: 2556541 old 2: ('&no','&name','&addr','&city','&phone') new 2: ('5','ankit','laxmi road','pune','2556541') 1 row created. SQL> select * from sup156; NO NAME -------------- -----------------1 manish 2 vishal 3 kunal 4 sudhir 5 ankit 11 mr patel 6 rows selected. SQL> desc item156; Name Null? ----------------------------------------------------------------ITEM_NO NOT NULL ITEM_NAME QUANTITY Type -------VARCHAR2(20) VARCHAR2(20) NUMBER(20) ADDR CITY PHONE -------------------- -------------------- ----------------kothrud pune 26356263 bandra mumbai 3225665 hinjawadi pune 4556002 ganesh nagar nasik 3556541 laxmi road pune 2556541 amravati baramati 3225456

SQL> insert into item156 values 2 ('&item_no','&item_name','&quantity'); Enter value for item_no: 6 Enter value for item_name: mouse Enter value for quantity: 550 old 2: ('&item_no','&item_name','&quantity') new 2: ('6','mouse','550') 1 row created. SQL> / Enter value for item_no: 7 Enter value for item_name: keyboard Enter value for quantity: 120 old 2: ('&item_no','&item_name','&quantity') new 2: ('7','keyboard','120') 1 row created. SQL> / Enter value for item_no: 8 Enter value for item_name: monitor Enter value for quantity: 650 old 2: ('&item_no','&item_name','&quantity') new 2: ('8','monitor','650') 1 row created. SQL> / Enter value for item_no: 9 Enter value for item_name: CPU Enter value for quantity: 250 old 2: ('&item_no','&item_name','&quantity') new 2: ('9','CPU','250') 1 row created. SQL> / Enter value for item_no: 10 Enter value for item_name: ups Enter value for quantity: 1200 old 2: ('&item_no','&item_name','&quantity') new 2: ('10','ups','1200') 1 row created.

SQL> select * from item156; ITEM_NO ITEM_NAME QUANTITY -------------- -------------------- -----------------6 mouse 550 7 keyboard 120 8 monitor 650 9 CPU 250 10 ups 1200 SQL> desc sup_item156 Name Null? -------------------------------------- --------RATE DISCOUNT NO ITEM_NO Type --------------NUMBER(9,2) NUMBER(7,2) VARCHAR2(20) VARCHAR2(20)

SQL> insert into sup_item156 values 2 ('&rate','&discount','&no','&item_no'); Enter value for rate: 11100 Enter value for discount: 1110 Enter value for no: 1 Enter value for item_no: 6 old 2: ('&rate','&discount','&no','&item_no') new 2: ('11100','1110','1','6') 1 row created. SQL> / Enter value for rate: 15000 Enter value for discount: 1500 Enter value for no: 2 Enter value for item_no: 7 old 2: ('&rate','&discount','&no','&item_no') new 2: ('15000','1500','2','7') 1 row created. SQL> / Enter value for rate: 20000 Enter value for discount: 200 Enter value for no: 3 Enter value for item_no: 8 old 2: ('&rate','&discount','&no','&item_no') new 2: ('20000','200','3','8') 1 row created. SQL> / Enter value for rate: 65000 Enter value for discount: 2500

Enter value for no: 4 Enter value for item_no: 9 old 2: ('&rate','&discount','&no','&item_no') new 2: ('65000','2500','4','9') 1 row created. SQL> / Enter value for rate: 85000 Enter value for discount: 4500 Enter value for no: 5 Enter value for item_no: 10 old 2: ('&rate','&discount','&no','&item_no') new 2: ('85000','4500','5','10') 1 row created. SQL> / Enter value for rate: 23000 Enter value for discount: 1200 Enter value for no: 11 Enter value for item_no: 6 old 2: ('&rate','&discount','&no','&item_no') new 2: ('23000','1200','11','6') 1 row created. SQL> select * from sup_item156; RATE DISCOUNT ------------- --------------11100 1110 15000 1500 20000 200 65000 2500 85000 4500 23000 1200 6 rows selected. Q No 1: List all the details of items having quantity > 500 SQL> select * from item156 2 where quantity>500; ITEM_NO ITEM_NAME QUANTITY -------------- -------------------- ---------------6 mouse 550 8 monitor 650 10 ups 1200 NO ITEM_NO ---------- ---------------1 6 2 7 3 8 4 9 5 10 11 6

Q No 2: Increase the 5% rate of the item mouse SQL> update sup_item156 2 SET rate=rate-rate*0.05 3 where item_no='6'; 2 rows updated. SQL> select * from sup_item156; RATE DISCOUNT ------------- -----------------10518.64 1110 15000 1500 20000 200 65000 2500 85000 4500 21795.38 1200 6 rows selected. Q No 3: Display the item details supplied by the supplier Mr. Patil SQL> select item156.*,name from item156,sup156,sup_item156 2 where sup156.no=sup_item156.no and 3 item156.item_no=sup_item156.item_no 4 and name like 'mr patel'; ITEM_NO ITEM_NAME QUANTITY NAME ------------- -------------------- --------------- -------6 mouse 550 mr patel Q No 4: Count the number of suppliers from each city SQL> select count(no),city from sup156 2 GROUP BY city 3 ; COUNT(NO) CITY ---------------- --------------1 baramati 1 mumbai 1 nasik 3 pune NO -------1 2 3 4 5 11 ITEM_NO --------------6 7 8 9 10 6

Roll No:156 Name: Kiran Shinde Assignment No 14: Consider the following Entities & Relationships Student(Rollno, sname, birthdate) Course(Cno, Cname, Course_fee, Duration) Student and Course are related with many to many relationships. Constraints: Primary key, Course fee should be > 0 Create a RDB in 3NF & write queries in Oracle 8i for following. Count the number of courses joined by Nilesh List the name of all students who have joined for course c++ Display details of course having maximum fee. List course wise Student names along with course fee and duration

SQL> create table stud156 2 (rool_no varchar2(20) primary key, 3 s_name varchar2(20), 4 birth_date date); Table created.

SQL> create table course156 2 (c_no varchar2(20) primary key, 3 c_name varchar2(20), 4 c_fee number(10), 5 duration varchar2(20), 6 CHECK (c_fee>0)); Table created. SQL> create table stud_course156 2 (rool_no varchar2(20) references stud156(rool_no), 3 c_no varchar2(20) references course156(c_no)); Table created. SQL> desc stud156; Name Null? Type ----------------------------------------------------------------- ------------------------ROOL_NO NOT NULL VARCHAR2(20) S_NAME VARCHAR2(20) BIRTH_DATE DATE SQL> insert into stud156 values 2 ('&rool_no','&s_name','&birth_date'); Enter value for rool_no: 1 Enter value for s_name: sudhir Enter value for birth_date: 25-jan-1993 old 2: ('&rool_no','&s_name','&birth_date') new 2: ('1','sudhir','25-jan-1993') 1 row created. SQL> / Enter value for rool_no: 2 Enter value for s_name: satish Enter value for birth_date: 12-dec-1992 old 2: ('&rool_no','&s_name','&birth_date') new 2: ('2','satish','12-dec-1992') 1 row created. SQL> / Enter value for rool_no: 3 Enter value for s_name: nilesh Enter value for birth_date: 20-feb-1990 old 2: ('&rool_no','&s_name','&birth_date') new 2: ('3','nilesh','20-feb-1990') 1 row created. SQL> select * from stud156;

ROOL_NO S_NAME BIRTH_DATE -------------- --------------- -------------------1 sudhir 25-JAN-93 2 satish 12-DEC-92 3 nilesh 20-FEB-90 SQL> desc course207 Name Null? Type ----------------------------------------------------------------- ------------------------C_NO NOT NULL VARCHAR2(20) C_NAME VARCHAR2(20) C_FEE NUMBER(10) DURATION VARCHAR2(20) SQL> insert into course156 values 2 ('&c_no','&c_name','&c_fee','&duration'); Enter value for c_no: 10 Enter value for c_name: c++ Enter value for c_fee: 6000 Enter value for duration: 4 months old 2: ('&c_no','&c_name','&c_fee','&duration') new 2: ('10','c++','6000','4 months') 1 row created. SQL> / Enter value for c_no: 11 Enter value for c_name: sid infotech Enter value for c_fee: 10000 Enter value for duration: 2 months old 2: ('&c_no','&c_name','&c_fee','&duration') new 2: ('11','sid infotech','10000','2 months') 1 row created. SQL> / Enter value for c_no: 12 Enter value for c_name: java Enter value for c_fee: 5000 Enter value for duration: 6 months old 2: ('&c_no','&c_name','&c_fee','&duration') new 2: ('12','java','5000','6 months') 1 row created. SQL> / Enter value for c_no: 13 Enter value for c_name: MS-CIT Enter value for c_fee: 5000 Enter value for duration: 3 months old 2: ('&c_no','&c_name','&c_fee','&duration')

new 2: ('13','MS-CIT','5000','3 months') 1 row created. SQL> select * from course156; C_NO -------------10 11 12 13 C_NAME C_FEE -------------------- --------------c++ 6000 sid infotech 10000 java 5000 MS-CIT 5000 DURATION --------------4 months 2 months 6 months 3 months

SQL> desc stud_course207 Name Null? Type --------------------------------------------------------- -------------------------ROOL_NO VARCHAR2(20) C_NO VARCHAR2(20) SQL> insert into stud_course156 values 2 ('&rool_no','&c_no'); Enter value for rool_no: 3 Enter value for c_no: 10 old 2: ('&rool_no','&c_no') new 2: ('3','10') 1 row created. SQL> / Enter value for rool_no: 3 Enter value for c_no: 13 old 2: ('&rool_no','&c_no') new 2: ('3','13') 1 row created. SQL> / Enter value for rool_no: 1 Enter value for c_no: 11 old 2: ('&rool_no','&c_no') new 2: ('1','11') 1 row created. SQL> / Enter value for rool_no: 2 Enter value for c_no: 12 old 2: ('&rool_no','&c_no') new 2: ('2','12') 1 row created.

SQL> / Enter value for rool_no: 2 Enter value for c_no: 13 old 2: ('&rool_no','&c_no') new 2: ('2','13') 1 row created. SQL> / Enter value for rool_no: 1 Enter value for c_no: 13 old 2: ('&rool_no','&c_no') new 2: ('1','13') 1 row created. SQL> select * from stud_course156; ROOL_NO ------------3 3 1 2 2 1 C_NO -------------10 13 11 12 13 13

6 rows selected. Q No 1: Count the number of courses joined by Nilesh SQL> select count(course156.c_no)"nilesh joint" from course156,stud156,stud_course156 2 where stud156.rool_no=stud_course156.rool_no and 3 course156.c_no=stud_course156.c_no 4 and s_name like 'nilesh'; nilesh joint -----------2 Q No 2: List the name of all students who have joined for course c++ SQL> select s_name,c_name from course156,stud156,stud_course156 2 where stud156.rool_no=stud_course156.rool_no and 3 course156.c_no=stud_course156.c_no 4 and c_name like 'c++'; S_NAME C_NAME ---------------- -------------------nilesh c++

Q No 3: Display details of course having maximum fee. SQL> select course156.* from course156 where c_fee=(select max(c_fee) from course156); C_NO C_NAME C_FEE DURATION --------------- -------------------- -------------- -------------------11 sid infotech 10000 2 months Q No 4: List course wise Student names along with course fee and duration SQL> select c_name,s_name,c_fee,duration from course156,stud156,stud_course156 2 where course156.c_no=stud_course156.c_no and 3 stud156.rool_no=stud_course156.rool_no group by c_name,s_name,c_fee,duration; C_NAME S_NAME C_FEE -------------------- -------------------- ---------c++ nilesh 6000 java satish 5000 MS-CIT nilesh 5000 MS-CIT satish 5000 MS-CIT sudhir 5000 sid infotech sudhir 10000 6 rows selected. DURATION ----------------4 months 6 months 3 months 3 months 3 months 2 months

Roll No:156 Name: Kiran Shinde Assignment No 15: Consider the following Entities & Relationships Teacher (tno, tname, collegename,dept) Exam(examtno, examname) Teacher and Exam related with many to many relationships. Constraints: Primary key, examname should not be null Create a RDB in 3NF & write queries in Oracle 8i for following. Find department of teacher Mrs. Jadhav of D.Y.Patil College List all teachers who have given SET examination. Count the number of teachers of MJC College List College wise teacher name with examination given by teacher

SQL> create table teacher156 2 (t_no varchar2(20) primary key, 3 t_name varchar2(20), 4 college_name varchar2(20), 5 dept varchar2(20));

Table created. SQL> create table exam156 2 (exam_no varchar2(20) primary key, 3 exam_name varchar2(20) NOT NULL); Table created. SQL> create table teach_exam156 2 (t_no varchar2(20) references teacher156(t_no), 3 exam_no varchar2(20) references exam156(exam_no)); Table created. SQL> desc teacher156; Name Null? ----------------------------------------- --------------T_NO NOT NULL T_NAME COLLEGE_NAME DEPT Type ---------------------VARCHAR2(20) VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> insert into teacher156 values 2 ('&t_no','&t_name','&college_name','&dept'); Enter value for t_no: 1 Enter value for t_name: mrs jadhav Enter value for college_name: D.Y.patil Enter value for dept: BCS old 2: ('&t_no','&t_name','&college_name','&dept') new 2: ('1','mrs jadhav','D.Y.patil','BCS') 1 row created. SQL> / Enter value for t_no: 2 Enter value for t_name: ms oboroy Enter value for college_name: MJC Enter value for dept: BCA old 2: ('&t_no','&t_name','&college_name','&dept') new 2: ('2','ms oboroy','MJC','BCA') 1 row created. SQL> / Enter value for t_no: 3 Enter value for t_name: mrs karan Enter value for college_name: MJC Enter value for dept: BSC old 2: ('&t_no','&t_name','&college_name','&dept') new 2: ('3','mrs karan','MJC','BSC')

1 row created. SQL> / Enter value for t_no: 4 Enter value for t_name: mrs lalit Enter value for college_name: MJC Enter value for dept: MCA old 2: ('&t_no','&t_name','&college_name','&dept') new 2: ('4','mrs lalit','MJC','MCA') 1 row created. SQL> / Enter value for t_no: 5 Enter value for t_name: mrs patel Enter value for college_name: D.Y.patil Enter value for dept: MCS old 2: ('&t_no','&t_name','&college_name','&dept') new 2: ('5','mrs patel','D.Y.patil','MCS') 1 row created. SQL> / Enter value for t_no: 6 Enter value for t_name: sadanand Enter value for college_name: MITSOM Enter value for dept: BCA old 2: ('&t_no','&t_name','&college_name','&dept') new 2: ('6','sadanand','MITSOM','BCA') 1 row created. SQL> select * from teacher156; T_NO -------------1 2 3 4 5 6 T_NAME -------------------mrs jadhav ms oboroy mrs karan mrs lalit mrs patel sadanand COLLEGE_NAME --------------------D.Y.patil MJC MJC MJC D.Y.patil MITSOM DEPT -----------BCS BCA BSC MCA MCS BCA

6 rows selected. SQL> desc exam207 Name Null? --------------------------------------------------------------EXAM_NO NOT NULL EXAM_NAME NOT NULL SQL> insert into exam156 values Type ---------------------VARCHAR2(20) VARCHAR2(20)

2 ('&exam_no','&exam_name'); Enter value for exam_no: 10 Enter value for exam_name: SET old 2: ('&exam_no','&exam_name') new 2: ('10','SET') 1 row created. SQL> / Enter value for exam_no: 11 Enter value for exam_name: ON SET old 2: ('&exam_no','&exam_name') new 2: ('11','ON SET') 1 row created. SQL> / Enter value for exam_no: 12 Enter value for exam_name: MCS old 2: ('&exam_no','&exam_name') new 2: ('12','MCS') 1 row created. SQL> select * from exam156; EXAM_NO -------------10 11 12 EXAM_NAME ------------------SET ON SET MCS

SQL> desc teach_exam156 Name Null? Type -----------------------------------------------------------------------------------T_NO VARCHAR2(20) EXAM_NO VARCHAR2(20) SQL> insert into teach_exam156 values 2 ('&t_no','&exam_no'); Enter value for t_no: 1 Enter value for exam_no: 10 old 2: ('&t_no','&exam_no') new 2: ('1','10') 1 row created. SQL> / Enter value for t_no: 2 Enter value for exam_no: 12 old 2: ('&t_no','&exam_no') new 2: ('2','12')

1 row created. SQL> / Enter value for t_no: 3 Enter value for exam_no: 10 old 2: ('&t_no','&exam_no') new 2: ('3','10') 1 row created. SQL> / Enter value for t_no: 4 Enter value for exam_no: 11 old 2: ('&t_no','&exam_no') new 2: ('4','11') 1 row created. SQL> / Enter value for t_no: 5 Enter value for exam_no: 10 old 2: ('&t_no','&exam_no') new 2: ('5','10') 1 row created. SQL> / Enter value for t_no: 6 Enter value for exam_no: 10 old 2: ('&t_no','&exam_no') new 2: ('6','10') 1 row created. SQL> select * from teach_exam156; T_NO -------1 2 3 4 5 6 EXAM_NO -------------------10 12 10 11 10 10

6 rows selected.

Q No 1: Find department of teacher Mrs. Jadhav of D.Y.Patil College SQL> select * from teacher156 2 where t_name like 'mrs jadhav' 3 and college_name like 'D.Y.patil'; T_NO T_NAME COLLEGE_NAME DEPT -------------- ---------------- -------------------- -----------------1 mrs jadhav D.Y.patil BCS Q No 2: List all teachers who have given SET examination. SQL> select t_name,exam_name from teacher156,exam156,teach_exam156 2 where teacher156.t_no=teach_exam156.t_no and 3 exam156.exam_no=teach_exam156.exam_no 4 and exam_name like 'SET'; T_NAME EXAM_NAME -------------------- -------------------mrs jadhav SET mrs karan SET mrs patel SET sadanand SET Q No 3: Count the number of teachers of MJC College SQL> select count(t_name) from teacher156 2 where college_name like 'MJC'; COUNT(T_NAME) -----------------------3 Q No 4: List College wise teacher name with examination given by teacher SQL> select teacher156.college_name,teacher156.t_name,exam_name from teacher156,exam156,teach_exam156 2 where teacher156.t_no=teach_exam156.t_no and 3 exam156.exam_no=teach_exam156.exam_no 4 GROUP BY college_name,t_name,exam_name; COLLEGE_NAME ------------------MJC MJC MJC MITSOM D.Y.patil D.Y.patil 6 rows selected. T_NAME -----------------mrs karan mrs lalit ms oboroy sadanand mrs patel mrs jadhav EXAM_NAME ----------------SET ON SET MCS SET SET SET

Potrebbero piacerti anche