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

Assignment 2 (1)

The document outlines the creation of several database tables and functions related to projects, employees, students, and subjects. It includes SQL commands for creating tables, inserting data, and defining functions to retrieve specific details from the database. Additionally, it demonstrates the use of SELECT statements to query the data and return results.

Uploaded by

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

Assignment 2 (1)

The document outlines the creation of several database tables and functions related to projects, employees, students, and subjects. It includes SQL commands for creating tables, inserting data, and defining functions to retrieve specific details from the database. Additionally, it demonstrates the use of SELECT statements to query the data and return results.

Uploaded by

hellosachin5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

As

signment2
Setd(
proj
ect
-empl
oyee)
s
hine=
#cr
eat
etabl
epr
oj(
pnoi
ntpr
imar
ykey
,pnamec
har
(30)
,pt
ypec
har
(20)
,dur
ati
oni
nt)
;

CREATETABLE

s
hine=
#cr
eat
etabl
eemp0(
empnoi
ntpr
imar
ykey
,enamec
har
(20)
,j
dat
edat
e);

CREATETABLE

s
hine=
#cr
eat
etabl
ep_
e(pnoi
ntr
efer
enc
espr
oj(
pno)
,empnoi
ntr
efer
enc
esemp0(
empno)
);

CREATETABLE

s
hine=
#ins er
tintoproj
v
alues(
1,'
formulae'
,
'stat
ist
ics
',
3),
(2,
'
tabl
es'
,
'mat
hs'
,
2),
(3,
'
par
agr
aph
',
'eng
lis
h',
4);

I
NSERT03

sh
ine=#ins
erti
ntoemp0v
alues
(11
,'
kis
han'
,
'1998-
09-
03'
),
(12,
'
rah
ul'
,
'1990-
03-
24'
),
(13,
'
om'
,
'2000-
05-
15'
);

I
NSERT03

s
hine=
#al
tert
abl
ep_
eadds
tar
tdat
edat
e;

ALTERTABLE

s
hine=
#sel
ect*f
romp_
e;

pno|empno|s
tar
tdat
e

-
--
--
+--
--
--
-+-
--
--
--
--
--

(
0rows
)

s
hine=
#ins
erti
ntop_
eval
ues
(1,
11,
'
2004-
09-
04'
),
(2,
12,
'
2007-
10-
24'
),
(3,
13,
'
201
1-04-
19'
);

I
NSERT03

s
hine=
#sel
ect*f
rompr
oj;

pno| pname | pt
ype |dur
ati
on

-
--
--
+--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
+--
--
--
--
--
--
--
--
--
--
--
+--
--
--
--
--

1|f
ormul
ae |s
tat
ist
ics | 3

2|t
abl
es |mat
hs | 2

3|par
agr
aph |eng
lis
h | 4

(
3rows
)
s
hine=
#sel
ect*f
romemp0;

empno| ename |j
dat
e

-
--
--
--
+--
--
--
--
--
--
--
--
--
--
--
+--
--
--
--
--
--

1
1|ki
shan |1
998-
09-
03

1
2|r
ahul |1
990-
03-
24

1
3|om |2000-
05-
15

(
3rows
)

s
hine=
#sel
ect*f
romp_
e;

pno|empno|s
tar
tdat
e

-
--
--
+--
--
--
-+-
--
--
--
--
--
-

1| 1
1|2004-
09-
04

2| 1
2|2007-
10-
24

3| 1
3|201
1-04-
19

(
3rows
)

#ques
tion1

s
hine=#creat
eorreplacefunc
tiondetail
(tex
t)retur
nsv
oidas'decl
arerrec
ord;
beg
in
s
electint
orpnamef romprojwhereptype=$1
;rais
enoti
ce''
proj
ectname
i
s=%'
',
r.
pname;end;
'
languag
e'pl
pgsql'
;

CREATEFUNCTI
ON

s
hine=
#sel
ectdet
ail
('
mat
hs'
);

NOTI
CE:pr
ojec
tnamei
s=t
abl
es

det
ail

-
--
--
--
-

(
1row)

#ques
tion2

s
hine=
#cr
eat
eorr
epl
acef
unc
tionpdet
ls(
tex
t)r
etur
nsv
oidas'
dec
lar
err
ecor
d;beg
in
selectint
or*f romproj
,emp0,p_ewh er
eemp0.ename=$1andemp0.
empno=
p_e.
empnoand
proj.
pno=p_e.
pno;rai
senotice'
'pno=%pname=%ptype=%
duration=
%''
,r
.pno,
r.
pname,r
.ptype,
r.
durati
on;
end;'
lang
uage'pl
pgs
ql'
;

CREATEFUNCTI
ON

s
hine=
#sel
ectpdet
ls(
'om'
);

NOTI
CE:pno=
3 pname=
par
agr
aph pt
ype=
eng
lis
h dur
ati
on=
4

pdet
ls

-
--
--
--
-

(
1row)

#ques
tion3

shi
ne=
#c reateorrepl
acefunc
tioncnt
emp(t
ext)returnsintas'declarerrecord;begi
nsel
ect
int
orcount(emp0.
empno)ascf r
omemp0,proj
,p_ewherepr oj
.
pname= $1and
emp0.
empno= p_e.
empnoandproj.
pno=
p_e.
pno;retur
n( r
.c);
end; '
language'pl
pgsql'
;

CREATEFUNCTI
ON

s
hine=
#sel
ectc
ntemp(
'par
agr
aph
');

c
ntemp

-
--
--
--
-

(
1row)

Sete(
student
-subj
ect
)
s
hine=#creat
etabl
est
un(
rol
lnoi
ntpr
imar
ykey
,namev
arc
har
(30)
,addr
essv
arc
har
(50)
,cl
ass
v
archar(
10));

CREATETABLE

s
hine=
#cr
eat
etabl
esubj
(sc
odev
arc
har
(10)pr
imar
ykey
,subnamev
arc
har
(20)
);

CREATETABLE

s
hine=#cr
eatet
abl
es t
_sub(
rol
lnoi
ntr
efer
enc
ess
tun(
rol
lno)
,sc
odev
arc
har
(10)r
efer
enc
es
s
ubj(s
code),
mar
ksint
);

CREATETABLE

s
hine=
#insertint
os t
un
v
alues(
1,'
vai
shnavi'
,
'vadg
aon'
,
'f
y'
),
(2,
'
punam'
,
'di
ghi
'
,'
sy'
),
(3,
'
har
sh'
,
'al
andi
'
,'
ty
');

I
NSERT03
s
hine=
#ins
erti
ntos
ubjv
alues
('1
A',
'
sci
enc
e')
,('
1B'
,
'mat
hs'
),
('
1C'
,
'sc
ienc
e')
;

I
NSERT03

s
hine=
#ins
erti
ntos
t_s
ubv
alues
(1,
'
1A'
,
78)
,(2,
'
1B'
,
90)
,(3,
'
1C'
,
89)
;

I
NSERT03

s
hine=
#sel
ect*f
roms
tun;

r
oll
no|name |addr
ess|c
las
s

-
--
--
--
-+-
--
--
--
--
--
+--
--
--
--
-+-
--
--
--

1|v
ais
hnav
i|v
adg
aon|f
y

2|punam |di
ghi|s
y

3|h
ars
h |al
andi|t
y

(
3rows
)

s
hine=
#sel
ect*f
roms
ubj
;

s
code|s
ubname

-
--
--
--
+--
--
--
--
-

1
A |s
cienc
e

1
B |mat
hs

1
C |s
cienc
e

(
3rows
)

s
hine=
#sel
ect*f
roms
t_s
ub;

r
oll
no|s
code|mar
ks

-
--
--
--
-+-
--
--
--
+--
--
--
-

1|1
A | 78

2|1
B | 90

3|1
C | 89

(
3rows
)

#ques
tion1
s
hine=#c reateorreplac
efuncti
onstudetl
s(i
nt)retur
nsvoi
das'
dec
lar
err
ecor
d;beg
in
s
electintor*f roms t
unwhererol
lno=$1
;rais
enot i
ce'
'%%%
%''
,
r.
rollno,r
.name,r
.addr
ess,
r.
cl
ass;end;'
languag
e'plpgs
ql'
;
CREATEFUNCTI
ON

s
hine=
#sel
ects
tudet
ls(
2);

NOTI
CE:2punamdi
ghis
y

s
tudet
ls

-
--
--
--
--
-

(
1row)

#ques
tion2
s
h i
ne=#createorrepl
acef
unc
tionst
dtl
s(t
ext)ret
urnsvoidas'
declar
err ec
ord;
begins
elec
t
i
ntor*froms tunwher
ename=
$1 ;
rai
senot
ice'
'%%%%'',
r.
roll
no,
r.
name,r
.addr
ess,
r.
cl
ass;
end;
'
languag
e'plpgsql
';

CREATEFUNCTI
ON

s
hine=
#sel
ects
tdt
ls(
'vai
shnav
i'
);

NOTI
CE:1v
ais
hnav
ivadg
aonf
y

s
tdt
ls

-
--
--
--
-

(
1row)

#ques
tion3
s
h i
ne=#c r
eateorrepl
acefunct
ionc ursor
d(text)ret
urnsvoidas'
declarerrecord;
curcur
sor
f
ors el
ect*fromstunwher
ec l
ass =$1;beg
inopenc ur;l
oopfetchc
uri nt
or;exitwhennot
f
ound; r
aisenot
ice'
'%%%%''
,r
.r
ollno,r
.name,r
.address,
r.
clas
s;endloop;c
los
ec ur;
end;
'
language'pl
pgsql
';

CREATEFUNCTI
ON

s
hine=
#sel
ectc
urs
ord(
'f
y'
);

NOTI
CE:1v
ais
hnav
ivadg
aonf
y

c
urs
ord

-
--
--
--
--

(
1row)

You might also like