Sunteți pe pagina 1din 7

ASSIGNMENT

Batch : 2010-12

Session : 2011-12

Course Code : MS-151

Programme: MBA

Semester : I/II

Course Title : ITM Lab

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

Course Code : MS-151

Course Title : ITM Lab

Programme: MBA

Semester : III/IV

Lab Exercise
(Constraints on the table)

Column or Table level Constraints


1. Create a table Employee with certain data entry restrictions:
-

Emp_no should be a primary key

Emp_name, Designation and Date_of_join should not be empty.

Salary should be greater than 5000.

Date_of_join should be greater than Dec-2000 and less than Jan-2009.

Column Name

Datatype and size

Emp_no

Number (5)

Emp_name

Varchar2 (30)

Designation

Char (10)

Date_of_join

Date

Salary

Number (9,2)

Dept_no

Number (2)

Add records to Employee table.

Constraints on Existing tables


2.

Write the SQL command to make Dept_no of Department table a primary key.

Foreign Key constraint

3. Create table Allowance and modify table Employee with the following specification:

Column Name

Data type and size

Column Name

Data type and size

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

Course Code : MS-151

Course Title : ITM Lab

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),

constraint fk_sn foreign key(salesman_no)references salesman_master(salesman_no),


constraint chk check(dely_date>order_date));
1.e
create table sales_order_details(order_no varchar2(6),
product_no varchar2(6),
qty_ordered number(8),
qty_disp number(8),
product_rate number(10,2),
constraint pk_sod primary key(order_no,product_no),
constraint fk_on foreign key(order_no)references sales_order(order_no),
constraint fk_pn foreign key(product_no)references product_master(product_no));
2.a
insert into
client_master(client_no,name,city,pincode,state,bal_due)values('&client_no','&name','&city',&pincode,'
&state',&bal_due);
2.b
insert into product_master values('&product_no','&description',&profit_percent,'&unit_measure',
&qty_on_hand,&reorder_lvl,&sell_price,&cost_price);
2.C
insert into salesman_master values('&salesman_no','&salesman_name','&address1','&address2','&ci
ty','&pincode','&state',&sal_amt,&tgt_to_get,&ytd_sales,'&Remarks');
2.d
insert into sales_order(order_no,order_date,client_no,dely_type,billed_yn,salesman_no,dely_dat
e,order_status)values('&order_no','&order_date','&client_no','&dely_type','&billed_yn','&salesman_no'
,'&daly_date','&order_status');
2.e
insert into sales_order_details values('&order_no','&product_no',&qty_orderes,&qty_disp,&produc
t_rate);
3.a
select name from client_master where name like '_a%';
3.b
select city from client_master where city like '_a%';
3.c
select name from client_master where city =Bombayor city=Delhi;
3.d
select name from client_master where bal_due>10000;
3.e
select * from sales_order where order_date like ___JAN%;
3.f
select * from sales_order where client_no=C00001or client_no=C00002;
3.g
select * from product_master where sell_price between 2001 and 5000;
3.h
select
product_no,description,unit_measure,qty_on_hand,reorder_lvl,sell_price,cost_price,(sell_price*0.15)N
ew Rate from product_master where sell_price >1500;

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;

S-ar putea să vă placă și