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

Lab Manual 10

This document contains instructions for creating tables, inserting data, and performing queries in Oracle SQL. It defines tables for salesmen, customers, and orders, then provides exercises to add constraints, insert sample data, and write queries to join tables and return selected columns where certain conditions are met. The exercises focus on manipulating the schema using ALTER TABLE and CREATE statements, as well as writing SQL queries using keywords like SELECT, FROM, WHERE, INNER JOIN, and ORDER BY.

Uploaded by

sing bling
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Lab Manual 10

This document contains instructions for creating tables, inserting data, and performing queries in Oracle SQL. It defines tables for salesmen, customers, and orders, then provides exercises to add constraints, insert sample data, and write queries to join tables and return selected columns where certain conditions are met. The exercises focus on manipulating the schema using ALTER TABLE and CREATE statements, as well as writing SQL queries using keywords like SELECT, FROM, WHERE, INNER JOIN, and ORDER BY.

Uploaded by

sing bling
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Database Administration & Management Lab

Lab Manual 10
Create table “Salesman”:
Create table salesmen
( sid varchar2(5) primary key,
sname varchar2(20) not null,
city varchar2(15) not null,
salary number(5,2),
product varchar2(20),
tgttoget number(5,2),
comm number(5,2) );

Create table “Customers”:


Create table customerss

( cid varchar2(5) primary key,

cname varchar2(20) not null,

city varchar2(15) not null,

state varchar2(15),

pincode number(10),

product varchar2(20),
class char (1) );

Create table “Orders”:


Create table orders
( oid varchar2(5) primary key,
cid varchar2(5),
sid varchar2(5),
product varchar2(20),
qty number(5),
odate date,
o_amt number(8,2) );
Insert in table “Salesman”:

Insert in table “Customerss”:

Insert in table “Orders”:


Exercise 1
1. Add primary key and Foreign Key to the existing tables using alter tablecommand.
Alter table orders drop primary key;

Alter table orders add primary key(oid);

Alter table orders add(comm references salesmen);

2. Create cust table which contains cno having pk, cname and occupation where data. Values
inserted for cno must start with the capital letter C and cname should be inupper case.
Create table cust
(cno varchar(20) primary key,
cname varchar(30),
occupation varchar(50));
insert into cust (cno,cname,occupation) values('C601','tooba','manager');

3. Find out the name of all the salesmen having „a‟ as the second letter in their names.

Select sname from salesmen where sname like '_a%';

4. List all the information of customers whose state contains null value.
Select * from customerss where state is null;
5. List all the information of customers in descending order according to their name.

Select * from customerss order by cname desc;

Exercise 2
1. Display customer no, name, city and order amount.
Select customerss.cid,
customerss.cname,
customerss.city,
orders.o_amt from customerss inner join orders on customerss.cid=orders.cid;
2. Display salesman details with their order details.
Select salesmen.sid,
salesmen.sname,
salesmen.city,orders.oid,
orders.cid,orders.sid,
orders.o_amtfrom salesmen inner join orders on salesmen.sid=orders.sid;

3. Display customer info of salesman S102 and S105.


Select customerss.cid, customer.cname, customerss.city, orders.sid, orders.oid from customerss inner
join orders.cid=customerss.cid where orders.sid in(‘s102’, ‘s105’);
4. List the salesmen details along with customers names associated with them.

Select salesmen.sid, salesmen.sname from salesmen inner join orders on salesmen.sid=orders.sid

union all select customerss.cid,customerss.cname from customerss inner join orders on


customerss.cid=orders.cid;

Exercise 3
Create User 1:
Create User 2:

Create Role 1:

Create Role 2:

Grant Privileges to role 1:


Grant Privileges to role 2:

Grant roles to users:

You might also like