C 13 Part 2
C 13 Part 2
l (21 , 'el ect ron i cs' ),(13, 'leat her' ),( 19, 'wood' ),
( 79 , 'eatable' ),( 59 , 'constructi on' )
f]itd pna:me brandid cid modEfy.car pnce
~I
II l ,til [aptnp 451 2.1 2IK16 35000
...
~
2 12 soap 845 6J
13
2000 52
·1sOCHl
3 14 safa 615 1900
4 ]4. fiih~s 121 59 2D16 JOOO
II 5 42 hed g1 19 1996 10000
6 85 oiseur~ 85 79 200] 25
[ill
, cld cname
['131re~lher
2 19 wood
IJ 2, el'ec:tronrSJ
4 59 conslruction
5 63 u,111elries
15 79 ealobfe
- ' -
EJ create table pproducts (pid int primary key,
pname varchar (20 ) not null, brandid int unique ,
cid int foreign key references pcategories (cid ),
modelyear int not null, price int not null)
E) create table pcategories ( cid int primary key ,
l cname varchar (20) not null)
select * from pproducts
select * from pcategories
EJ insert into pproducts values
(15, ' smart watch' , 452, 21, 2006, 3000 ) , (14, 'sofa' , 615 , 13 , 1990, 1500
(42, ' bed ' , 91 , 19, 1996, 10000 ),( 85 , 'biscui t ' , 85 , 79, 2003 , 25 ),
( 34, ' tiles ' , 121 , 59 , 2016 , 3000 )
E) insert into pcategories values (63 , ' toiletries ' ),
l (21 , ' electronics' ),( 13, ' leather ' ),( 19, ' wood ' ),
(79 , ' eatable' ),( 59 , 'construction' )
~ select pname , cname , price from pproducts inner join pcategories
Lon pproducts . cid=pcategories . cid
E] select c . cname , p . pname , count (p . pid ) from pproducts p
wood
~p
bed ,
E] create table employee ( empid int primary key ,
l
efname varchar ( 20 ) not null, elname varchar (20 ) not null,
age int check(age>21 ), emailid varchar (25 ) un ique ,
phno bigint not null, address varchar (20 ) not null)
select * f rom employee
insert into employee values (l , 'vardhan ' , 'kuma r' , 22, '[email protected] ' , 9876543210, 'delhi ' )
insert into employee values (2, 'himani' , 'sharma ' , 32, ' [email protected] ' , 9977554422, ' mumbai' )
insert into employee values ( 3, 'aayushi' , ' shreshth ' , 24, ' [email protected] ' , 9977555121, 'kolkata' )
insert into employee values (4, 'hemanth' , ' sha r ma ' , 25 , ' [email protected]' , 9876545666, ' bengaluru' )
insert into employee values (5, 'swatee' , 'kapoor' , 26, ' [email protected]' , 9544567777, 'hyde r abad' )
E] create table project (pid int unique , empid int f oreign key references employee (empid ),
l cid int not null, pname varchar (20 ) not null, psd date default getdate ())
select * f rom project
a insert into project ( pid, empid, cid, pname ) values (111, 1, 3, 'project 1 ' ),( 222, 2, 1, 'pr oject 2' ),
l( 333, 3, 5, 'project 3 ' ),( 444, 3, 2, 'project ~ ' ),( 555 , 5, 4, ' project 5' )
..1..
empid efname elname age emailid phno a ddress
...
• i;t
1 I, j vardhan kumar 22 [email protected] 9876543210 delhi
...... 2
3
2
3
himani
aayushi
sharma
s hreshth
32
24
hima [email protected]
[email protected]
9977554422
9977555121
mumbai
kolkala
4 4 hemanth sharma 25 h [email protected] 9876545666 bengaluru
IIBl 5 5 swatee kapoor 26 [email protected] 9544567777 hyderabad
( li!l
135 % •
~ T-SQL rl Ill Results I ll!l Message
(No column Mm._ pid pneme
1 Iverdhlln kumar j 111 project 1
2 h1mani sharma 222 project 2
3 aayush, shreshlh 333 project 3
4 a ayushi slveshlh 444 project4
5 hemanlh sharma NULL NULL
6 swatee kaPoO< 555 project 5
~ create table project ( pid int unique, empid int foreign key references employee ( empid ),
Leid int not null, pname varchar ( 20) not null, ps d date default getdate ( ) )
select • from employee
select • from project
EJ insert into project ( pid , empid, cid, pname ) values ( 111, 1, 3, 'project 1' ) ,(222, 2, 1, ' project 2' ),
l (333, 3, 5, 'project 3' ) , (444, 3, 2, ' project 4' ) , ( 555, 5, 4, 'project 5' )
~ select efname+ ' ' +elname , pid, pname from employee left join proj ect
L on employee . empid=pr oj ect . empid
E] select e . empid, e . efname , count ( p . pid ) as pcount from employee e left join project p
l on e . empid=p. empid group by e . empid, e . efname order by pcount desc
35% ·I
g T-SQL ti Iii Results @I Message
emp1d efname pcount
I [i___j "ayushl 2
1 vardhan 1
2 himani
5 swatee 1
4 hemanU, 0