Documente Academic
Documente Profesional
Documente Cultură
Batch : 2010-12
Session : 2011-12
Programme: MBA
Semester : I/II
Lab Exercise
SQL 1
1. Create table Department with the following specification:
COLUMN NAMES
TYPE
SIZE
Dept_no
Number
Dept_name
Char
30
Dept_location
Char
20
2. Write the SQL command to view the structure of the above created table.
3. Add a record in the Department table (i.e. , for Dept_no 10 , with the Dept_name as Marketing
, Dept_loc as London )
4. Add the remaining records in the Department table as follows:
Dept_no Dept_name Dept_location
10
Marketing
London
20
Accounts
America
30
Sales
New York
40
Software
Boston
50
Production
Boston
5. Add a partially filled record in the Department table (i.e., for Dept_no 60, with the Dept_name
as HR)
6. Write the SQL command to display all the columns of the Department table.
7. Write the SQL command to display selective columns of the Department table such as
Dept_no, Dept_name.
8. Write the SQL command to increase the width of a column during display.
9. Write the SQL command to view the names of the existing tables created by the current user.
10. Management decides to store the Department Heads name for all the departments. We need to
add a column to the Department table. Write the SQL command to add a column named
Dept_Head_name of data type as Char and size as 20.
11. Write the SQL command to enter the names of all the department heads of the respective
departments.
ASSIGNMENT
Batch : 2010-12
Session : 2011-12
Programme: MBA
Semester : III/IV
Lab Exercise
(Constraints on the table)
Column Name
Emp_no
Number (5)
Emp_name
Varchar2 (30)
Designation
Char (10)
Date_of_join
Date
Salary
Number (9,2)
Dept_no
Number (2)
Write the SQL command to make Dept_no of Department table a primary key.
3. Create table Allowance and modify table Employee with the following specification:
Column Name
Column Name
Designation
Char(10), from
Emp_no
Number(5)
Employee table
Emp_name
Varchar2(30)
Designation
Char(10), from
SP_allowance
Number(8,2)
Conveyance
Number(8,2)
Allowance table
Date_of_join
Date
Salary
Number(8,2)
Dept_no
Number(2)
4.
(a) Create three tables as Allowance_dup and Employee_dup with the same structure and data as Allowance
and Employee table respectively.
(b) Remove all the constraints of all the three tables such as Allowance_dup, Employee_dup.
ASSIGNMENT
Batch : 2010-12
Session : 2011-12
Programme: MBA
Semester : III/IV
Lab exercise
1.a
create table client_master(client_no varchar2(6)primary key check(client_no like 'C%'),
name varchar2(20) not null,
address1 varchar2(30),
address2 varchar2(30),
City varchar2(15),
pincode number(8),
state varchar2(15),
bal_due number(10,2));
1.b
create table product_master(product_no varchar2(6)primary key check(product_no like 'P%'),
description varchar2(15)not null,
profit_percent number(4,2)not null,
unit_measure varchar2(10)not null,
qty_on_hand number(8)not null,
reorder_lvl varchar2(8)not null,
sell_price number(8,2)not null check(sell_price!=0),
cost_price number(8,2)not null check(cost_price!=0));
1.c
create table salesman_master(salesman_no varchar2(6)primary key check(salesman_no like 'S%'),
salesman_name varchar2(20)not null,
adress1 varchar2(30)not null,
adress2 varchar2(30),
city varchar2(20),
pincode varchar2(8),
State varchar2(20),
sal_amt number(8,2)not null check(sal_amt!=0),
tgt_to_get number(6,2)not null check(tgt_to_get!=0),
ytd_sales number(6,2)not null,
remarks varchar2(60));
1.d
create table sales_order(order_no varchar2(6)primary key check(order_no like 'O%'),
order_date date,
client_no varchar2(6),
dely_addr varchar2(25),
salesman_no varchar2(6),
dely_type char(1)default 'F',
billed_yn char(1),
dely_date date,
order_status varchar2(10),
constraint fk_cn foreign key(client_no)references client_master(client_no),
3.i
select name,city,state from client_master where state!='Maharastra';
3.j
select count(order_no)from sales_order;
3.k
select avg(sell_price)"Average price" from product_master;
3.l
select max(sell_price)max_price,min(sell_price)Min_pricefrom product_master;
3.m
select sum(qty_on_hand)>than1500from product_master where sell_price>=1500;
3.n
select * from product_master where qty_on_hand<reorder_lvl;
3.o
select order_no,order_date from sales_order;
3.p
select order_no,to_char(order_date,'Month DD,YYYY')"Order Date",to_char(dely_date,Month
DD,YYYY)dely date from sales_order;
3.q
select order_no,to_char(order_date,'DD-Month-YY')"Order Date",to_char(dely_date,DD- Month -YY)
dely datefrom sales_order;
3.r
select (sysdate+15)"date add" from dual;
3.s
select (dely_date-order_date)"days"from sales_order;