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

23BCE309_DBMS

Uploaded by

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

23BCE309_DBMS

Uploaded by

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

Create table client (used to store client information) having following attributes:

SQL> create table client

2 (clientno varchar2(6),

3 name varchar2(20),

4 city varchar2(15),

5 pincode number(8),

6 state varchar2(15),

7 baldue number(10,5));

Table created.

Create table product (used to store client information) having following attributes:

SQL> create table product

2 (productno varchar2(6),

3 description varchar2(15),

4 profitpercent number(4,2),

5 unitmeasure varchar2(10),

6 qtyonhand number(8),

7 reorderlvl number(8),

8 sellprice number(8,2),

9 costprice number(8,2));
Table created.

Create table salesman (used to store client information) having following attributes:

SQL> create table salesman

2 (salesmanno varchar2(6),

3 salesmanname varchar2(20),

4 address1 varchar2(30),

5 address2 varchar2(30),

6 city varchar2(20),

7 pincode number(8),

8 state varchar2(20),

9 salamt number(8,2),

10 tgttoget number(6,2),

11 ytdsales number(6,2),

12 remarks varchar2(60));

Table created.
Create table sales_order(used to store client information) having following attributes:

SQL> create table sales_order

2 (orderno varchar2(6),

3 clientno varchar2(6),

4 orderdate date,

5 salesmanno varchar2(6),

6 delaytype char(1),

7 billyn char(1),

8 delaydate date,

9 orderstatus varchar2(10));

Table created.

SQL> create table sales_order_details

2 (orderno varchar2(6),

3 productno varchar2(6),

4 qtyordered number(8),

5 productrate number(10,2));
Table created.

SQL> insert into client values('&clientno','&name','&city',&pincode,'&state',&baldue);

Enter value for clientno: C01

Enter value for name: Ivan Bayross

Enter value for city: Mumbai

Enter value for pincode: 400054

Enter value for state: Maharashtra

Enter value for baldue: 15000

old 1: insert into client values('&clientno','&name','&city',&pincode,'&state',&baldue)

new 1: insert into client values('C01','Ivan Bayross','Mumbai',400054,'Maharashtra',15000)

1 row created.

SQL> /

Enter value for clientno: C02

Enter value for name: Mamta Shah

Enter value for city: Chennai

Enter value for pincode: 780001

Enter value for state: Tamil Nadu

Enter value for baldue: 0

old 1: insert into client values('&clientno','&name','&city',&pincode,'&state',&baldue)

new 1: insert into client values('C02','Mamta Shah','Chennai',780001,'Tamil Nadu',0)

1 row created.
SQL> /

Enter value for clientno: C03

Enter value for name: Chhaya Patel

Enter value for city: Mumbai

Enter value for pincode: 400057

Enter value for state: Maharashtra

Enter value for baldue: 5000

old 1: insert into client values('&clientno','&name','&city',&pincode,'&state',&baldue)

new 1: insert into client values('C03','Chhaya Patel','Mumbai',400057,'Maharashtra',5000)

1 row created.

SQL> /

Enter value for clientno: C04

Enter value for name: ASHNI JOSHI

Enter value for city: BANGALORE

Enter value for pincode: 56001

Enter value for state: KARNATAKA Enter value for baldue: 0 old 1: INSERT INTO client

VALUES('&CLIENTNO','&NAME','&CITY',&PINCODE,'&STATE',&BALDUE) new 1: INSERT INTO

client VALUES('C04','ASHNI JOSHI','BANGALORE',56001,'KARNATAKA',0)

1 row created.

SQL> /

Enter value for clientno: C05

Enter value for name: HARSH DESAI

Enter value for city: MUMBAI

Enter value for pincode: 400060

Enter value for state: MAHARASHTRA


Enter value for baldue: 2000 old 1: INSERT INTO client

VALUES('&CLIENTNO','&NAME','&CITY',&PINCODE,'&STATE',&BALDUE) new 1: INSERT INTO client

VALUES('C05','HARSH DESAI','MUMBAI',400060,'MAHARASHTRA',2000)

1 row created.

SQL> /

Enter value for clientno: C06

Enter value for name: DEEPAK SHARMA

Enter value for city: MANGLORE

Enter value for pincode: 560050

Enter value for state: KARNATAKA Enter value for baldue: 0 old 1: INSERT INTO client

VALUES('&CLIENTNO','&NAME','&CITY',&PINCODE,'&STATE',&BALDUE) new 1: INSERT INTO

client VALUES('C06','DEEPAK SHARMA','MANGLORE',560050,'KARNATAKA',0)


SQL> INSERT INTO product
VALUES('&PRODUCTNO','&DESCRIPTION',&PROFITPERCENT,'&UNITMEASURE',&QTYONHAND,&REOR
DERLVL,&SELLPRICE,&COSTPRICE);

Enter value for productno: P00001

Enter value for description: 1.44 FLOPPIES

Enter value for profitpercent: 5

Enter value for unitmeasure: PIECE

Enter value for qtyonhand: 100

Enter value for reorderlvl: 20

Enter value for sellprice: 525 Enter

value for costprice: 500

old 1: INSERT INTO product


VALUES('&PRODUCTNO','&DESCRIPTION',&PROFITPERCENT,'&UNITMEASURE',&QTYONHAND,&REOR
DERLVL,&SELLPRICE,&COSTPRICE) new 1: INSERT INTO product VALUES('P00001','1.44
FLOPPIES',5,'PIECE',100,20,525,500)

1 row created.
SQL> /

Enter value for productno: P03453

Enter value for description: MONITORS

Enter value for profitpercent: 6

Enter value for unitmeasure: PIECE

Enter value for qtyonhand: 10

Enter value for reorderlvl: 3

Enter value for sellprice: 12000 Enter

value for costprice: 11200

old 1: INSERT INTO product


VALUES('&PRODUCTNO','&DESCRIPTION',&PROFITPERCENT,'&UNITMEASURE',&QTYONHAND,&REOR
DERLVL,&SELLPRICE,&COSTPRICE) new 1: INSERT INTO product

VALUES('P03453','MONITORS',6,'PIECE',10,3,12000,11200)

1 row created.

SQL> /

Enter value for productno: P06734

Enter value for description: MOUSE

Enter value for profitpercent: 5

Enter value for unitmeasure: PIECE

Enter value for qtyonhand: 20

Enter value for reorderlvl: 5

Enter value for sellprice: 1050 Enter

value for costprice: 500

old 1: INSERT INTO product


VALUES('&PRODUCTNO','&DESCRIPTION',&PROFITPERCENT,'&UNITMEASURE',&QTYONHAND,&REOR
DERLVL,&SELLPRICE,&COSTPRICE) new 1: INSERT INTO product
VALUES('P06734','MOUSE',5,'PIECE',20,5,1050,500)
SQL> /

Enter value for productno: P07865

Enter value for description: 1.22 FLOPIES

Enter value for profitpercent: 5

Enter value for unitmeasure: PIECE

Enter value for qtyonhand: 100

Enter value for reorderlvl: 20

Enter value for sellprice: 525 Enter

value for costprice: 500

old 1: INSERT INTO product


VALUES('&PRODUCTNO','&DESCRIPTION',&PROFITPERCENT,'&UNITMEASURE',&QTYONHAND,&REOR
DERLVL,&SELLPRICE,&COSTPRICE) new 1: INSERT INTO product VALUES('P07865','1.22

FLOPIES',5,'PIECE',100,20,525,500)

1 row created.

SQL> /

Enter value for productno: P07868

Enter value for description: KEYBOARDS

Enter value for profitpercent: 2

Enter value for unitmeasure: PIECE3

Enter value for qtyonhand: 10 Enter

value for reorderlvl: 3

Enter value for sellprice: 3150 Enter

value for costprice: 3050

old 1: INSERT INTO product


VALUES('&PRODUCTNO','&DESCRIPTION',&PROFITPERCENT,'&UNITMEASURE',&QTYONHAND,&REOR
DERLVL,&SELLPRICE,&COSTPRICE) new 1: INSERT INTO product
VALUES('P07868','KEYBOARDS',2,'PIECE3',10,3,3150,3050)
SQL> INSERT INTO salesman
VALUES('&SALESMANNO','&SALESMANNAME','&ADDRESS1','&ADDRESS2','&CITY',&PINCODE,'&STAT
E',&SALAMT,&TGTTOGET,&YTDSALES,'&REMARKS');

Enter value for salesmanno: S01

Enter value for salesmanname: AMAN

Enter value for address1: A/14

Enter value for address2: WORLI

Enter value for city: MUMBAI

Enter value for pincode: 400002

Enter value for state: MAHARASHTRA


Enter value for salamt: 3000

Enter value for tgttoget: 100

Enter value for ytdsales: 50

Enter value for remarks: GOOD

old 1: INSERT INTO salesman


VALUES('&SALESMANNO','&SALESMANNAME','&ADDRESS1','&ADDRESS2','&CITY',&PINCODE,'&STA
T E',&SALAMT,&TGTTOGET,&YTDSALES,'&REMARKS')

new 1: INSERT INTO salesman


VALUES('S01','AMAN','A/14','WORLI','MUMBAI',400002,'MAHARASHTRA',3000,100,50,'GOOD')

1 row created.

SQL> /

Enter value for salesmanno: S02

Enter value for salesmanname: OMKAR

Enter value for address1: 65

Enter value for address2: NARIMAN

Enter value for city: MUMBAI

Enter value for pincode: 400001

Enter value for state: MAHARASHTRA

Enter value for salamt: 3000

Enter value for tgttoget: 200

Enter value for ytdsales: 100

Enter value for remarks: GOOD

old 1: INSERT INTO salesman


VALUES('&SALESMANNO','&SALESMANNAME','&ADDRESS1','&ADDRESS2','&CITY',&PINCODE,'&STA
T E',&SALAMT,&TGTTOGET,&YTDSALES,'&REMARKS')

new 1: INSERT INTO salesman


VALUES('S02','OMKAR','65','NARIMAN','MUMBAI',400001,'MAHARASHTRA',3000,200,100,'GOOD')

1 row created.

SQL> /
Enter value for salesmanno: S03

Enter value for salesmanname: RAJ

Enter value for address1: P-7

Enter value for address2: BANDRA

Enter value for city: MUMBAI

Enter value for pincode: 400032

Enter value for state: MAHARASHTRA

Enter value for salamt: 3000

Enter value for tgttoget: 200

Enter value for ytdsales: 100

Enter value for remarks: GOOD

old 1: INSERT INTO salesman


VALUES('&SALESMANNO','&SALESMANNAME','&ADDRESS1','&ADDRESS2','&CITY',&PINCODE,'&STA
T E',&SALAMT,&TGTTOGET,&YTDSALES,'&REMARKS')

new 1: INSERT INTO salesman VALUES('S03','RAJ','P-


7','BANDRA','MUMBAI',400032,'MAHARASHTRA',3000,200,100,'GOOD')

1 row created.

SQL> /

Enter value for salesmanno: S04

Enter value for salesmanname: ASHISH

Enter value for address1: A/5

Enter value for address2: JUHU

Enter value for city: MUMBAI

Enter value for pincode: 400044

Enter value for state: MAHARSHTRA

Enter value for salamt: 3500

Enter value for tgttoget: 200

Enter value for ytdsales: 150

Enter value for remarks: GOOD

old 1: INSERT INTO salesman


VALUES('&SALESMANNO','&SALESMANNAME','&ADDRESS1','&ADDRESS2','&CITY',&PINCODE,'&STA
T E',&SALAMT,&TGTTOGET,&YTDSALES,'&REMARKS')

new 1: INSERT INTO salesman


VALUES('S04','ASHISH','A/5','JUHU','MUMBAI',400044,'MAHARSHTRA',3500,200,150,'GOOD')

1 row created.
SQL> INSERT INTO sales_order VALUES('O19001','C01','12-JAN-16','S01','F','N','20-JAN-16','IN
PROCESS');

1 row created.

SQL> INSERT INTO sales_order VALUES('O19002','C02','25-JAN-17','S02','P','N','27-JAN-


17','CANCELLED');

1 row created.

SQL> INSERT INTO sales_order VALUES('O46865','C03','18-FEB-17','S03','F','Y','20-FEB17','FULFILLED')


2 ;

1 row created.

SQL> INSERT INTO sales_order VALUES('019003','C01','03-APR-16','S01','F','Y','07-APR-


16','FULFLLED');

1 row created.

SQL> INSERT INTO sales_order VALUES('O46866','C04','20-MAY-16','S02','P','N','22-MAY-


16','CANCELLED');

1 row created.

SQL> INSERT INTO sales_order VALUES('019008','C05','24-MAY-16','S04','F','N','26-MAY-16','IN


PROCESS');

1 row created.
SQL> INSERT INTO sales_order_details VALUES('O19001','P00001',4,525)

1 row created.

SQL> INSERT INTO sales_order_details VALUES('O19001','P07965',2,8400)

1 row created.

SQL> INSERT INTO sales_order_details VALUES('O19001','P07885',2,5250)

1 row created.

SQL> INSERT INTO sales_order_details VALUES('O19002','P00001',10,525)

1 row created.

SQL> INSERT INTO sales_order_details VALUES('O46865','P07868',3,3150)

1 row created.

4. Do as directed:
a) Change the city of Harsh to Bangalore.
b) Change the city of salesman to Pune. What is wrong in doing this type of
query?
c) Delete all the salesmen whose salaries are equal to Rs. 3500.
d) Delete all the clients who live in “Tamil Nadu”.
e) Add a column called “Telephone” of data type “Number” and size “10” to
the client table.
f) Change the size of sell price to 6, 2. Observe the behavior.
g) Change the name of salesman table to sman.
h) Create a new table sales_order_new from sales_order containing data as well
as structure.
i) Create a new table order_details from sales_order_details containing only
the structure (no data).

a) update client set city = 'Bangalore' where name = 'Harsh Desai';


1 row updated.

b) update salesman set city = 'Pune';


4 rows updated.

What is wrong with this query?


Changing all salesmen's cities to Pune would overwrite individual city values, resulting in loss
of data integrity. Instead, update specific salesmen if needed.
c) delete from salesman where salamt = 3500;
1 row deleted.

d) delete from client where state = 'Tamil Nadu';


1 row deleted.

e) alter table client add telephone number(10);


Table altered.

f) alter table product modify sellprice number(6,2);


alter table product modify sellprice number(6,2)
ERROR at line 1:
ORA-01440: column to be modified must be empty to decrease precision or scale
Observation: If existing data exceeds the new size, this operation might
fail unless data complies with the new constraints.

g) rename salesman to sman;


Table renamed.

h) create table sales_order_new as select * from sales_order;


Table created.

i) create table order_details as select * from sales_order_details where 1=2;


Table created.

You might also like