0% found this document useful (0 votes)
19 views3 pages

P1

The document outlines SQL commands for creating and managing a database with tables for clients, products, salesmen, sales orders, and sales order details. It includes commands for inserting data, updating records, deleting entries, altering table structures, and creating new tables. Additionally, it provides examples of data manipulation and schema changes within the database.

Uploaded by

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

P1

The document outlines SQL commands for creating and managing a database with tables for clients, products, salesmen, sales orders, and sales order details. It includes commands for inserting data, updating records, deleting entries, altering table structures, and creating new tables. Additionally, it provides examples of data manipulation and schema changes within the database.

Uploaded by

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

-- 1.

a) Create table client


CREATE TABLE client (
clientno VARCHAR2(6),
name VARCHAR2(20),
city VARCHAR2(15),
pincode NUMBER(8),
state VARCHAR2(15),
baldue NUMBER(10, 5)
);

-- 1.b) Create table product


CREATE TABLE product (
productno VARCHAR2(6),
description VARCHAR2(15),
profitpercent NUMBER(4, 2),
unitmeasure VARCHAR2(10),
qtyonhand NUMBER(8),
reorderlvl NUMBER(8),
sellprice NUMBER(8, 2),
costprice NUMBER(8, 2)
);

-- 1.c) Create table salesman


CREATE TABLE salesman (
salesmanno VARCHAR2(6),
salesmanname VARCHAR2(20),
address1 VARCHAR2(30),
address2 VARCHAR2(30),
city VARCHAR2(20),
pincode NUMBER(8),
state VARCHAR2(20),
salamt NUMBER(8, 2),
tgttoget NUMBER(6, 2),
ytdsales NUMBER(6, 2),
remarks VARCHAR2(60)
);

-- 1.d) Create table sales_order


CREATE TABLE sales_order (
orderno VARCHAR2(6),
clientno VARCHAR2(6),
orderdate DATE,
salesmanno VARCHAR2(6),
delaytype CHAR(1),
billyn CHAR(1),
delaydate DATE,
orderstatus VARCHAR2(10)
);

-- 1.e) Create table sales_order_details


CREATE TABLE sales_order_details (
orderno VARCHAR2(6),
productno VARCHAR2(6),
qtyordered NUMBER(8),
productrate NUMBER(10, 2)
);

-- 2.a) Retrieve the structure of the tables


DESC client;
DESC product;
DESC salesman;
DESC sales_order;
DESC sales_order_details;

-- 3.a) Insert data into client table


INSERT INTO client VALUES ('C01', 'Ivan Bayross', 'Mumbai', 400054, 'Maharashtra',
15000);
INSERT INTO client VALUES ('C02', 'Mamta Shah', 'Chennai', 780001, 'Tamil Nadu',
0);
INSERT INTO client VALUES ('C03', 'Chhaya Patel', 'Mumbai', 400057, 'Maharashtra',
5000);
INSERT INTO client VALUES ('C04', 'Ashni Joshi', 'Bangalore', 560001, 'Karnataka',
0);
INSERT INTO client VALUES ('C05', 'Harsh Desai', 'Mumbai', 400060, 'Maharashtra',
2000);
INSERT INTO client VALUES ('C06', 'Deepak Sharma', 'Mangalore', 560050,
'Karnataka', 0);

-- 3.b) Insert data into product table


INSERT INTO product VALUES ('P00001', '1.44 Floppies', 5, 'Piece', 100, 20, 525,
500);
INSERT INTO product VALUES ('P03453', 'Monitors', 6, 'Piece', 10, 3, 12000, 11200);
INSERT INTO product VALUES ('P06734', 'Mouse', 5, 'Piece', 20, 5, 1050, 500);
INSERT INTO product VALUES ('P07865', '1.22 Floppies', 5, 'Piece', 100, 20, 525,
500);
INSERT INTO product VALUES ('P07868', 'Keyboards', 2, 'Piece', 10, 3, 3150, 3050);

-- 3.c) Insert data into salesman table


INSERT INTO salesman VALUES ('S01', 'Aman', 'A/14 Worli', 'Mumbai', 'Mumbai',
400002, 'Maharashtra', 3000, 100, 50, 'Good');
INSERT INTO salesman VALUES ('S02', 'Omkar', '65 Nariman', 'Mumbai', 'Mumbai',
400001, 'Maharashtra', 3000, 200, 100, 'Good');
INSERT INTO salesman VALUES ('S03', 'Raj', 'P-7 Bandra', 'Mumbai', 'Mumbai',
400032, 'Maharashtra', 3000, 200, 100, 'Good');
INSERT INTO salesman VALUES ('S04', 'Ashish', 'A/5 Juhu', 'Mumbai', 'Mumbai',
400044, 'Maharashtra', 3500, 200, 150, 'Good');

-- 3.d) Insert data into sales_order table


INSERT INTO sales_order VALUES ('O19001', 'C01', TO_DATE('12-01-16', 'DD-MM-YY'),
'S01', 'F', 'N', TO_DATE('20-01-16', 'DD-MM-YY'), 'In Process');
INSERT INTO sales_order VALUES ('O19002', 'C02', TO_DATE('25-01-17', 'DD-MM-YY'),
'S02', 'P', 'N', TO_DATE('27-01-17', 'DD-MM-YY'), 'Cancelled');
INSERT INTO sales_order VALUES ('O46865', 'C03', TO_DATE('18-02-17', 'DD-MM-YY'),
'S03', 'F', 'Y', TO_DATE('20-02-17', 'DD-MM-YY'), 'Fulfilled');
INSERT INTO sales_order VALUES ('O19003', 'C01', TO_DATE('03-04-16', 'DD-MM-YY'),
'S01', 'F', 'Y', TO_DATE('07-04-16', 'DD-MM-YY'), 'Fulfilled');
INSERT INTO sales_order VALUES ('O46866', 'C04', TO_DATE('20-05-16', 'DD-MM-YY'),
'S02', 'P', 'N', TO_DATE('22-05-16', 'DD-MM-YY'), 'Cancelled');
INSERT INTO sales_order VALUES ('O19008', 'C05', TO_DATE('24-05-16', 'DD-MM-YY'),
'S04', 'F', 'N', TO_DATE('26-05-16', 'DD-MM-YY'), 'In Process');

-- 3.e) Insert data into sales_order_details table


INSERT INTO sales_order_details VALUES ('O19001', 'P00001', 4, 525);
INSERT INTO sales_order_details VALUES ('O19001', 'P07965', 2, 8400);
INSERT INTO sales_order_details VALUES ('O19001', 'P07885', 2, 5250);
INSERT INTO sales_order_details VALUES ('O19002', 'P00001', 10, 525);
INSERT INTO sales_order_details VALUES ('O46865', 'P07868', 3, 3150);
-- 4.a) Change the city of Harsh to Bangalore
UPDATE client SET city = 'Bangalore' WHERE name = 'Harsh Desai';

-- 4.b) Change the city of salesman to Pune


UPDATE salesman SET city = 'Pune';
-- This will update the city for all rows, which might not be desirable.

-- 4.c) Delete all the salesmen whose salaries are equal to Rs. 3500
DELETE FROM salesman WHERE salamt = 3500;

-- 4.d) Delete all the clients who live in "Tamil Nadu"


DELETE FROM client WHERE state = 'Tamil Nadu';

-- 4.e) Add a column called "Telephone" of data type "Number" and size "10" to the
client table
ALTER TABLE client ADD (telephone NUMBER(10));

-- 4.f) Change the size of sell price to 6, 2


ALTER TABLE product MODIFY (sellprice NUMBER(6, 2));
-- Behavior depends on existing data in the table. Data truncation might occur if
values exceed the new size.

-- 4.g) Change the name of salesman table to sman


RENAME salesman TO sman;

-- 4.h) Create a new table sales_order_new from sales_order containing data as well
as structure
CREATE TABLE sales_order_new AS SELECT * FROM sales_order;

-- 4.i) Create a new table order_details from sales_order_details containing only


the structure (no data)
CREATE TABLE order_details AS SELECT * FROM sales_order_details WHERE 1 = 0;

You might also like