Sei sulla pagina 1di 16

1.

Create a table client_master (Client_no, name,address1, address2, city, pin,


state,bal_due). Ensure that client_no starts with C.
create table client_master(
client_no varchar2(10) check (client_no like (C%)),
name varchar2(50),
address1 varchar2(100),
address2 varchar2(100),
city varchar2(50),
pin nmber(!),
state varchar2(10),
bal_de nmber(10)
)"

2. Cleant table product_master (prod_no, diecription, profitpercent, unitmeasure,
tyonhand, reorderl!l, sellprice, costprice). Ensure that product_no is primary "ey.
#nclude an appropriate constraint so that sellin$ price if a product is $reate than or
eual to cost price.
create table prodct_master(
prod_no nmber(10) primary key,
description varchar2(100),
pro#itpercent nmber($),
nitmeasre varchar2(20),
%tyonhand nmber(10),
reorderlvl nmber(10),
sellprice nmber(10) ,
costprice nmber(10),
C&'()*+,') price C-.C/ (sellprice 01 costprice)
)"

%. Create Client_no as primary "ey in client_master table.
alter table client_master modi#y(client_no varchar2(50) check(client_no like C%) primary
key )"

&. 'dd appropriate constraint so that prod_no of product_master table starts with
(.
alter table prodct_master modi#y(2rod_no varchar2(50) check(2rod_no like 2%) primary
key )"

). #nsert the followin$ *ecords in Client_master table+
insert into client_master ( C3,.')_'&, '+4. , C,)5 , 2,' , ()+). , 6+3_78.)
vales( C00019 , ,van 6ayross , 4mbai , :0005:9 , 4aharastra , 15000 )"

insert into client_master ( C3,.')_'&, '+4. , C,)5 , 2,' , ()+). , 6+3_78.)
vales( C00029 , 4amta m;mdar , 4adras , <=00019 , )amil 'ad , 0 )"

insert into client_master ( C3,.')_'&, '+4. , C,)5 , 2,' , ()+). , 6+3_78.)
vales( C000$9 , Chhaya 6ankar , 4mbai , :0005<9 , 4aharastra , 5000 )"

insert into client_master ( C3,.')_'&, '+4. , C,)5 , 2,' , ()+). , 6+3_78.)
vales( C000:9 , +sh>ini ?oshi , 6an@alore , 5!00019 , /arnataka , 0 )"

insert into client_master ( C3,.')_'&, '+4. , C,)5 , 2,' , ()+). , 6+3_78.)
vales( C00059 , -ansel Colaco , 4mbai , :000!09 , 4aharastra , 2000 )"

insert into client_master ( C3,.')_'&, '+4. , C,)5 , 2,' , ()+). , 6+3_78.)
vales( C000!9 , 7eepak (harma , 4an@alore , 5!00509 , /arnataka , 0 )"

,. #nsert the followin$ records in product_master table+
insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 200019 , )Dshirts , 5 , 2iece , 200 , 50 , $50 , 250 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20$:59 , (hirts , ! , 2iece , 150 , 50 , 500 , $50 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20!<$:9 , Cotto ?eans , 5 , 2iece , 100 , 20 , !00 , :50 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20<=!59 , Eeans , 5 , 2iece , 100 , 20 , <50 , 500 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20<=!=9 , )rosers , 2 , 2iece , 150 , 50 , =50 , 550 )"


insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20<==59 , 2ll &vers , 2F5 , 2iece , =0 , $0 , <00 , :50 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20<G!59 , 7enim (hirts , : , 2iece , 100 , :0 , $50 , 250 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20<G<59 , 3ycra )ops , 5 , 2iece , <0 , $0 , $00 , 1<5 )"

insert into prodct_master ( 2*&7_'& , 7.(C*,2),&' , 2*&A,)2.*C.') ,
8',)4.+(8*. , B)5&'-+'7 , *.&*7.*3C3 , (.332*,C. , C&()2*,C. )
vales ( 20==!59 , (kirts , 5 , 2iece , <5 , $0 , :50 , $00 )"

-. .ind /ut the names of all clients.
select name #rom client_master"

0. *etrie!e entire contents of client_master.
select H #rom client_master"

1. 2ist name, city and state of all clients.
select name, city, state #rom client_master"

13. 2ist all clients who are located in 4umbai.
select H #rom client_master >here city14mbai"

11. 2ist all products a!ailable in product_master table.
select H #rom prodct_master"

12. 2ist all products a!ailable in product_master table where product name starts with
5 or 6.
select H #rom prodct_master >here description like )% or description like (%"

1%. Chan$e the city of client_no C333) to 7an$alore.
pdate client_master set state16an@alore >here client_no1C00059"

1&. Chan$e the bal_due of client_no C33331 to 1333.
pdate client_master set bal_de11000 >here client_no1C00019"

1). Create a new table cl_master from client_master with all its data.
create table c1_master ( C3,.')_'& , '+4., +77*.((1, +77*.((2, C,)5, 2,',
()+)., 6+3_78.) as select C3,.')_'&, '+4., +77*.((1, +77*.((2, C,)5, 2,',
()+)., 6+3_78. #rom client_master"

1,. Create a new table 8 products from product_master that includes prod_no,
description, sellprice, costprice.
create table prodcts ( 2*&7_'&, 7.(C*,2),&', (.332*,C., C&()2*,C.) as select
2*&7_'&, 7.(C*,2),&', (.332*,C., C&()2*,C. #rom prodct_master"

1-. 9elete records of all clients not residin$ in 4umbai from c1_master
delete #rom c1_master >here city I0 4mbai"

10. *emo!e all products ha!in$ sell price $reater than or eual to )33 from products
table.
delete #rom prodcts >here sellprice01500"

11. 'dd Column Contact_no to c1_master table.
alter table c1_master add(contact_no nmber(10))"

23. Chan$e the si:e of sell price column in products to 13,2. ;ote what happens.
alter table prodcts modi#y(sellprice nmber(10,2))"
.**&*J column to be modified must be empty to decrease precision or scale

21. Chan$e the si:e of costprice column in products to ,,2. ;ote what happens.
alter table prodcts modi#y(costprice nmber(!,2))"
.**&*J column to be modified must be empty to decrease precision or scale

22. *emo!e column address1 from c1_master.
alter table c1_master drop(address1)"

2%. *ename c1_master to client.
rename c1_master to client"

2&. 2ist the client who stay in the city whose first letter is m.
select H #rom client_master >here city like 4%"

2). 2ist the name of all clients ha!in$ a as the second letter in their names.
select H #rom client_master >here name like _a%"

2,. 2ist all clients who stay in 7an$alore or 4an$alore.
select H #rom client_master >here city16an@alore or city14an@alore"

2-. 2ist all the clients whose 7al_due is $reater than 1333 and less than ,333.
select H #rom client_master >here bal_de bet>een 1000 and !000"
or
select H #rom client_master >here bal_de011000 and bal_deI1!000"

20. 2ist all clients who do not ha!e any 7al_due.
select H #rom client_master >here bal_de10"

21. 2ist products whose sellin$ price is $reater than )33 and less than or eual to -)3.
select H #rom prodct_master >here (.332*,C. 01500 and (.332*,C. I1<50"

%3. 2ist products whose sellin$ price is more than )33. Calculate new sellin$ price with
an increase of 1)< in the ori$inal sellin$ price. 9isplay it as ;ew (rice.
select 2*&7_'&, 7.(C*,2),&', 2*&A,)2.*C.'), 8',)4.+(8*., B)5&'-+'7,
*.&*7.*3C3, (.332*,C., C&()2*,C., ( sellprice K (sellpriceH0F15)) as ne>_salary
#rom prodct_master >here sellprice0500"

%1. 2ist the names, city and state of clients who are not in the state of maharastra.
select '+4., C,)5, ()+). #rom client_master >here ()+). I0 maharastra"

%2. 9etermine the ma=imum and minimum products prices. *ename the output as
ma=_price and 4in_price respecti!ely.
select min( sellprice ) as 4inimn_price, maL(sellprice) as 4aLimm_price #rom
prodct_master"

%%. Count the number of products ha!in$ price less than or eual to )33.
select cont( 7.(C*,2),&' ) #rom prodct_master >here sellprice bet>een 0 and 500"

%&. 2ist all products whose >ty/n?and is less than reorder le!el.
select H #rom prodct_master >here B)5&'-+'7I1*.&*7.*3C3"

%). 9elete data and structure of client table.
drop table client"

%,. 9elete data and structure of products table.
drop table prodcts"

MMMMMMMMMMMMMMMMMMMMMMM

BF$ Create Aollo>in@J
7ranch_4aster+
Column name 9ata type Constraint
6ranch_no 'mber(:) 2rimary key
6'ame Carchar2($0) 'ot 'll
3ocation Carchar2($0)

create table 6ranch_4aster (
6ranch_no nmber(:) primary key,
6'ame varchar2($0) not nll,
3ocation varchar2($0)
)"

6ranch_no 6'ame 3ocation
1 (aras>ati na@ar ,ndian 6ank 7holkpr
2 Carso>a brid@e ,ndian 6ank Carso>a
$ /F*F (in@h *oad ,ndian 6ank /ochin

insert into 6ranch_4aster vales( N6ranch_no, N6'ame, N3ocation
)"
&*
insert into 6ranch_4aster vales(1,(aras>ati na@ar ,ndian 6ank,O7holkpr)"
insert into 6ranch_4aster vales(2,Carso>a brid@e ,ndian 6ank,OCarso>a)"
insert into 6ranch_4aster vales($,/F*F (in@h *oad ,ndian 6ank,O/ochin)"

Customer_4aster+
Column name 9ata type Constraint
Cstomer_no 'mber(:) 2rimary key
C'ame Carchar2($0) 'ot 'll
Pender Char(1)
6irth_date 7ate
City Carchar2($0)
Contact_'o 'mber(10)

create table Cstomer_4aster (
Cstomer_no nmber(:) 2rimary key,
C'ame Carchar2($0) 'ot nll,
Pender char(1),
birth_date date,
city varchar2($0),
contact_no nmber(10)
)"

Customer_no C;ame @ender 7irth_date City Contact_;o
1 7harmesh 2atel 4ale 12D?nD<5 7elhi 2==$:<<0
2 /eval (in@h 4ale 1:D+@D<5 7elhi 2==:5<=0
$ 4inaLi 2atel Aemale 1$D?anD<! ?aipr 2<=::$:0
: /yati 2atil Aemale 1:DAebD<G 2ne $1=<$:20
5 ?ayant (in@h 4ale $1D7ecD=0 2ne $22!!:50

insert into Cstomer_4aster vales(1,7harmesh 2atel,O4,12D?nD<59,7elhi,2==$:<<0)"
insert into Cstomer_4aster vales(2,/eval (in@h,O4,1:D+@D<59,7elhi,2==:5<=0)"
insert into Cstomer_4aster vales($,4inaLi 2atel,OA,1$D?anD<!9,?aipr,2<=::$:0)"
insert into Cstomer_4aster vales(:,/yati 2atil,OA,1:DAebD<G9,2ne,$1=<$:20)"
insert into Cstomer_4aster vales(5,?ayant (in@h,O4,$1D7ecD=09,2ne,$22!!:50)"

'ccount_4aster+
Column name 9ata type Constraint
+ccont_'o 'mber(:) 2rimary key
+cc_)ype Char(2) 'ot 'll
6ranch_no 'mber(:) 'ot 'll, Aorei@n /ey
Cstomer_no 'mber(:) 'ot 'll, Aorei@n /ey
&pen_7ate 7ate
Crrent_6alance 'mber(!,2)

create table +ccont_4aster (
+ccont_'o 'mber(:) 2rimary key,
+cc_)ype Char(2) 'ot 'll,
6ranch_no 'mber(:) 'ot 'll re#erences 6ranch_4aster(6ranch_no),
Cstomer_no 'mber(:) 'ot 'll re#erences cstomer_4aster(Cstomer_no),
&pen_7ate 7ate,
Crrent_6alance 'mber(10,2)
)"

'ccount_;o 'cc_5ype 7ranch_no Customer_no /pen_9ate Current_7alance
101 (6 1 1 12D?anDGG :100FG
102 (6 1 2 0$DAebDGG 5200F<5
10$ C+ 2 1 2:DAebDGG 1000
10: (6 2 5 0$D4arDGG 25000
105 A7 2 2 0!D+@D00 10000
10! C+ $ $ 22D?anD01 :00
10< C+ $ 5 22DAebD01 !022F:5
10= (6 1 1 5D4ayD01 $000

insert into +ccont_4aster vales(101,(6,1,1,12D?anDGG9,:100FG)"
insert into +ccont_4aster vales(102,(6,1,2,0$DAebDGG9,5200F<5)"
insert into +ccont_4aster vales(10$,C+,2,1,2:DAebDGG9,1000)"
insert into +ccont_4aster vales(10:,(6,2,5,0$D4arDGG9,25000)"
insert into +ccont_4aster vales(105,A7,2,2,0!D+@D009,10000)"
insert into +ccont_4aster vales(10!,C+,$,$,22D?anD019,:00)"
insert into +ccont_4aster vales(10<,C+,$,5,22DAebD019,!022F:5)"
insert into +ccont_4aster vales(10=,C+,1,1,5D4ayD019,$000)"

6ol!e .ollowin$ >uery+

2ist all Customer 9etails.
select H #rom cstomer_master"

2ist all accounts 'ccount no, account type and current balance.
select +CC&8')_'&,+CC_)52.,C8**.')_6+3+'C. #rom +ccont_master"

@i!e 7ranch name for branch noA1.
select 6'ame #rom branch_master >here branch_no11"

6how all male customers name only.
select C'ame #rom cstomer_master >here Pender14O"

@i!e the distinct set of account types.
select distinct acc_type #rom accont_master"

.ind the customer ha!in$ more then one account.
select H #rom cstomer_master >here cstomer_no in (select cstomer_no #rom
accont_master @rop by cstomer_no havin@ cont(H)01)"

.ind Customer ha!in$ no account.
select H #rom cstomer_master >here C8()&4.*_'& not in (select distinct cstomer_no
#rom accont_master)"

.ind the customers detail that has atBleast one account.
select distinct cstomer_masterFC8()&4.*_'&,cstomer_masterFC'+4. #rom
cstomer_master,accont_master >here cstomer_masterFC8()&4.*_'& 1
accont_masterFC8()&4.*_'&"

2ist all customers ha!in$ sa!in$ ban" account only.
select distinct cstomer_masterFC8()&4.*_'&,cstomer_masterFC'+4. #rom
cstomer_master,accont_master >here cstomer_masterFC8()&4.*_'& 1
accont_masterFC8()&4.*_'& and accont_masterFacc_type1(6"

2ist all records where account opened in year 1111.
select distinct cstomer_masterFC8()&4.*_'&,cstomer_masterFC'+4. #rom
cstomer_master,accont_master >here cstomer_masterFC8()&4.*_'& 1
accont_masterFC8()&4.*_'& and .Q)*+C)(year #rom
accont_masterFopen_date)11GGG"

2ist all records where current balance not less then &333.
select H #rom cstomer_master,accont_master >here cstomer_masterFC8()&4.*_'& 1
accont_masterFC8()&4.*_'& and accont_masterFcrrent_6alance 0 :000"

2ist all branch names where branch no either 1 or %.
select 6'ame #rom branch_master >here 6ranch_no11 or 6ranch_no1$"

2ist all customers are whose contact line series start by 200.
select H #rom cstomer_master >here Contact_'o like 2==%"

'rran$e all accounts details in descendin$ order.
select H #rom accont_master order by accont_no desc"

2ist all details whose account openin$ date is not relayin$ in year 2333.
select H #rom accont_master, cstomer_master >here
accont_masterFcstomer_no1cstomer_masterFcstomer_no and eLtract(year #rom
accont_masterFopen_date) I0 2000"

2ist all customers whose last name is (atel.
select H #rom cstomer_master >here C'+4. like % 2atel"

9educt 1)33 repees from account_no 13).
pdate accont_master set crrent_balance1crrent_balanceD(1500) >here accont_no1105"

@i!e )33 rupees increment to account which is in Cersowa branch.
pdate accont_master set crrent_balance1crrent_balanceK500 >here branch_no1(select
branch_no #rom branch_master >here location1Carso>a)"

@i!e )33 rupees increment to account opened in Danuary.
pdate accont_master set crrent_balance1crrent_balanceK500 >here eLtract(month #rom
open_date)11"

6et City to @andhina$ar for all customers where contact no seriese start by 2.
pdate cstomer_master set city1Phasndhina@ar >here contact_no like 2%"

*emo!e all accounts which are opened after .eb 2331.
delete #rom accont_master >here eLtract(year #rom open_date) 0 2001 and eLtract (month
#rom open_date) 0 2"

*emo!e all current accounts from Eochins branch.
delete #rom accont_master >here branch_no1(select branch_no #rom branch_master >here
3&C+),&'1/ochin)"

5runcated 'CC/F;5_4aster.
trncate table accont_master"

*emo!e all customers whose a$e is more then %3 years.
delete #rom cstomer_master >here ((sysdateDbirth_date)R$!5)0$0"

*emo!e all contact numbers for each customer.
delete contact_no #rom cstomer_master"

*emo!e all customers list that li!es in (une or Daipur.
delete #rom cstomer_master >here city12ne or city1?aipr"

*emo!e all branch details.
delete #rom branch_master"

'dd new column named as is'cti!e with datatype as Char(1) in 'ccount_4aster table
usin$ 'lter statement.
alter table accont_master add(is+ctive char(1))"

6et 9ata type to Carchar2()3) from city in Customer_4aster table.
alter table cstomer_master modi#y(city varchar2(50))"

*emo!e the column named as contact number from Customer_4aster tables schema.
alter table cstomer_master drop (contact_no)"

Create new table b"_Cust_4ast from Customer_4aster tables schema.
create table bk_cst_mast (C8()&4.*_'& , C'+4. , P.'7.* , 6,*)-_7+). ,
C,)5 ) as
select C8()&4.*_'&, C'+4. , P.'7.* , 6,*)-_7+). , C,)5 #rom
cstomer_master"

*ename table name from customer_4aster by ;ew_Customer_2ist.
rename cstomer_master to 'e>_Cstomer_3ist"

*emo!e all the tables 'ccount_4aster, Custome_4aster, 7"_Cust_4ast,
7ranch_4aster.
drop table accont_master"
drop table cstomer_master"
drop table bk_cst_mast"
drop table branch_master"

Potrebbero piacerti anche