Sie sind auf Seite 1von 4

Name:

Registration Number:

Section:

G:

SET-1
Table 1: PROGRAMMER
PNAME (NVARCHAR(10)), DOB (DATE), DOJ (DATE), SEX (CHAR(1)), PROF1
(NVARCHAR(6)), PROF2 (NVARCHAR(6)), SAL (NUMERIC(10,2))
Create table Programmer (
PNAME nvarchar(10),dob date, doj date, sex char(1), prof1 nvarchar(6), prof2
nvarchar(6), sal numeric(10,2))

Table 2: SOFTWARE
S_ID (NVarchar(6)), TITLE (NVARCHAR(15)), DEVIN (NVARCHAR(10)), SCOST
(NUMERIC(10)), DCOST (NUMERIC(10)), SOLD (NUMERIC(10))
Create table Software (
S_ID NVarchar(6), TITLE NVARCHAR(15), DEVIN NVARCHAR(10), SCOST NUMeric(10),
DCOST NUMERIC(10), SOLD NUMERIC(10))

Table 3: STUDIES
SPLACE (NVARCHAR(10)), COURSE (NVARCHAR(10)), CCOST (NUMBER(10))
Create table Studies (
SPLACE NVARCHAR(10), COURSE NVARCHAR(10), CCOST NUMERIC(10))

LEGEND :
PNAME Programmer Name, SPLACE Study Place, CCOST Course Cost, DEVIN
Developed in, SCOST Software Cost, DCOST Development Cost, PROF1
Proficiency 1
NOTE: There could be a programmer who has not developed any software title, so
take this point into consideration.
1. Insert a column PId (nVarchar(6)) having values which starts only with C or
O and is the primary key to the programmer table and column
MGR(NVarchar(6)) to the programmers table.
alter table Programmer add mgr nvarchar(6) ,pid nvarchar(6) primary key
alter table Programmer add constraint chk1 check(pid like 'O%' or pid like 'C%')

2. Insert a column PId (NVarchar(6)) into the software table being the foreign
key to the programmer table. (ALSO Add PID column as the foreign key
in the studies table to the EMP table)

alter table Software add pid nvarchar(6) foreign key references Programmer(pid)

3. Set the default value of the SPLACE in the studies table to LPU and put a
constraint that the CCOST cannot be less than 0. (write two separate queries
for the default value and constraint)
alter table Studies add constraint con1 default 'LPU' for SPLACE;
alter table Studies add constraint con2 check(CCOST>0)

Name:

Registration Number:

Section:

G:

SET-1
PROGRAMMER
PNAME DOB
Harsh
17DEC1989
Chirag
21MAR1990
Anu
23MAR1987
Ravinde 25-JANr
1987

DOJ
23-JUL2012

SEX
M

PROF1
C

PROF2
C++

SAL
50000

PID
C1

MGR

21-JUL2012

Java

55000

O2

O3

21-JUL2012

Java

55000

O3

23-JUL2012

VB

40000

C4

C1

Insert into Programmer Values ('HARSH','12/17/1989','07/23/2012','M','C','C+


+',50000,'C1',NULL);
Insert into Programmer Values
('CHIRAG','03/21/1990','07/21/2012','M','C','JAVA',55000,'O2','O3');
Insert into Programmer Values
('ANU','03/23/1987','07/21/2012','F','C','JAVA',55000,'O3',NULL);
Insert into Programmer Values
('RAVINDER','01/25/1987','07/23/2012','M','C','VB',40000,'C4','C1');

SOFTWARE
S_ID
TITLE
S1
CProject
S2
VBProject
S3
JavaProjec
t
S4
JavaProjec
t2
S5
VBProject
2
Insert
Insert
Insert
Insert
Insert

into
into
into
into
into

STUDIES
SPLACE
LPU
LPU
LPU

Software
Software
Software
Software
Software

DEVIN
C
VB
Java

SCOST
5000
8000
15000

DCOST
2000
5000
10000

SOLD
5
4
2

PID
C4
C4
O2

Java

20000

15000

O3

VB

7000

4500

C4

Values
Values
Values
Values
Values

('S1','CPROJECT','C',5000,2000,5,'C4');
('S2','VBPROJECT','VB',8000,5000,4,'C4');
('S3','JAVAPROJECT','JAVA',15000,10000,2,'O2');
('S4','JAVAPROJECT2','JAVA',20000,15000,1,'O3');
('S5','VBPROJECT2','VB',7000,4500,3,'C4');

Course
Oracle
Java
Advanced Java

CCOST
5000
8000
12000

Insert into Studies Values ('LPU','ORACLE',5000,'C1');


Insert into Studies Values ('LPU','JAVA',8000,'O2');
Insert into Studies Values ('LPU','AD. JAVA',12000,'O3');

PID
C1
O2
O3

4. Create a table Programmer_Details having columns P_Id, PNAME, SAL, S_ID,


TITLE from the Programmer and Software table respectively.

Name:

Registration Number:

Section:

G:

SET-1
select Programmer.pid,PNAME,S_ID,TITLE into programmer_detail from Programmer,Software
where Programmer.pid=Software.pid

5. Delete the values from the Programmer_Details table and insert into the table
by taking the values from the source tables.
Truncate table programmer_detail
select * into programmer_detail from Programmer.

6. Calculate the total number of employees who developed project in C, VB


and JAVA and display the projects in descending order.
Select count(distinct pid) ,devin from software group by devin having devin IN
('C','VB','Java')
order by desc.
7. List all the software details and the corresponding programmers who
developed that software.

8. From the programmer table list the result like (Employee name followed
by Manager name)

Employee name | Manager Name


select p1.pname as employee_name ,p2.pname as
manager_name from programmer pa, programmer p2where
p1.mgr=p2,pid
9. List the total number of projects developed by Employee Chirag, Anu and
Ravinder and list them in descending order depending upon the total number
of projects developed by them.
Select count(pid) ,pname from programmer p ,software s where s.pid=p.pid group
by pname having pname order by count(sid) desc.
10.
Create a View EMPDETAIL with columns PID, PNAME, SAL, S_ID, TITLE
from Programmer and the software table respectively. Would this view be
updatable?
11.
Create the stored procedure to know the Title of the software,
DeveloperID (Programmer ID who developed that software),

Name:

Registration Number:

Section:

G:

SET-1
Developer (Programmer Name who made that software) and
Revenue (Profit generated by selling the software) when user enters
the SID of the software. Let the default value of the software be S1.
12.
Create a function which returns the programmer experience in years
by passing the DOJ of the programmer into the function.
Create function f1(@d as date)
returns numeric(4,2)
as
begin
Declare @temp numeric(4,2)
select @temp=datedif(d,@d,GETDATE())
returns (@tmp/365)
end
13.
Create a function which returns the pid, pname and sal of the
programmers hired between the year1 and year2 where the values of year1
and year2 would be entered by the user. Set default value of the year1=2010
and yer2= 2015.
create function yr(@ year1 as date,@year2 as date)
returns table
as
begin
select pid,PNAME,SAL from programmer where year(doj) between @year1,@year2
CREATE TABLE LOGCHANGES
(
SNO INT IDENTITY(1,1),
PID Nvarchar(6), -- tto capture the pid of the programmer whose salary is
updated
OSAL numeric(10,2),-- old salary of programmer
NSAL numeric(10,2), -- updated salary of programmer
dt date);

14.
Create a trigger which logs the changes made to the salary of
the programmer into the above created table.

Das könnte Ihnen auch gefallen