0% found this document useful (0 votes)
6 views5 pages

DB LAB 5

Uploaded by

Gabriel Panea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

DB LAB 5

Uploaded by

Gabriel Panea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

create database dbSecretariatNou

on
primary(name=Secretariat04,
filename='C:\DB\Secretariat_nou.mdf',
size=10,maxsize=40,
filegrowth=2)
log on
(name=Secretariat04_log,
filename='C:\DB\Secretariat_nou_log.ldf',
size=10,maxsize=20,
filegrowth=2)
go

use dbSecretariat04_05

CREATE TABLE tblStudent (


Nrleg char (8) PRIMARY KEY CLUSTERED,
CNP varchar (13) UNIQUE,
NumeStudent varchar (40) NOT NULL,
InitialaStudent varchar(6) ,
PrenumeStudent varchar (40) NOT NULL,
Sex char (1) CHECK (Sex IN ('M','F'))DEFAULT('M'),
DataNastere datetime,
GrupaSinge varchar (3) ,
StareCivila char (1) CHECK (StareCivila IN ('C','D','M','N','V')),
SituatiaMilitara char(1) CHECK (SituatiaMilitara IN ('I','N')),
Grupa char (5) CHECK (Grupa LIKE '10%')
)

CREATE TABLE tblTelefonStud(


Nrleg char (8) NOT NULL,
NrTelefon varchar (10) ,
Interior varchar (4) ,
Observatii varchar (30) ,
CONSTRAINT conTel_FK
FOREIGN KEY (NrLeg) REFERENCES tblStudent (Nrleg)
ON DELETE CASCADE ON UPDATE CASCADE
)

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102345','0766558341',12,'personal')

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102346','0766553331',NULL,'acasa')

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102347','0756758341',NULL,'personal')

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102348','0761238341',NULL,'servici')

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102349','0766558890',12,'acasa')

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102350','0766558456',12,'personal')

insert into tblTelefonStud (NrLeg,NrTelefon,Interior,Observatii)


values('102351','0766551111',12,'personal')
delete from tblTelefonStud where NrLeg='102348'
select * from tblTelefonStud

CREATE TABLE tblMaterie(


ID_Materie char (6) PRIMARY KEY CLUSTERED,
NumeMaterie varchar (30) NOT NULL,
Semestrul varchar (2) NOT NULL,
OreCurs tinyint,
OreSeminar tinyint,
OreLaborator tinyint,
OreProiect tinyint,
TipMaterie varchar (1) CHECK(TipMaterie IN ('F','N','0')) DEFAULT ('N'),
FormaExaminare varchar (3) CHECK (FormaExaminare IN ('E','CFN','CN')) DEFAULT
('E'),
Credit tinyint CHECK (Credit BETWEEN 1 AND 6)
)

CREATE TABLE tblStudiaza(


Nrleg char (8)NOT NULL REFERENCES tblStudent (Nrleg)
ON DELETE CASCADE ON UPDATE CASCADE,
ID_Materie char (6)NOT NULL REFERENCES tblMaterie (ID_Materie)
ON DELETE CASCADE ON UPDATE CASCADE
)

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102345','1840612163219', 'Popa' ,'M.', 'Dan', 'A', 'N', 'I')

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102346','1840614463219', 'Andreescu' ,'G.', 'Dana', 'B', 'N', 'N')

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102347','1560614463619', 'Andrei' ,'J.', 'Alex', 'A', 'N', 'N')

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102348','1840618765219', 'Tudor' ,'L.', 'Mara', 'A', 'C', 'I')

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102349','1865438765221', 'Grigore' ,'N.', 'Cristina', 'B', 'C', 'N')

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102350','1869876545221', 'Gri' ,'P.', 'Doru', 'A', 'N', 'N')

insert into tblStudent


(Nrleg,CNP,NumeStudent,InitialaStudent,PrenumeStudent,
GrupaSinge,StareCivila,SituatiaMilitara)
values('102351','1869870005221', 'Popescu' ,'P.', 'Boris', 'A', 'D', 'N')
select * from tblStudent

insert into tblMaterie values ('M001', 'Analiza matematica 1', '1', 3, 2, 0, 0,


'N', 'E', 4)
insert into tblMaterie values ('M002', 'Analiza matematica 2', '1', 3, 2, 0, 0,
'N', 'E', 4)
insert into tblMaterie values ('A001', 'Algebra', '1', 3, 2, 0, 0, 'N', 'E', 4)
insert into tblMaterie values ('P001', 'Programare', '1', 3, 2, 0, 0, 'N', 'E', 6)
insert into tblMaterie values ('M004', 'Analiza matematica 2', '2', 3, 2, 0, 0,
'N', 'E', 6)
insert into tblMaterie values ('P002', 'Tehnici de programare', '2', 3, 2, 0, 0,
'N', 'E', 3)
insert into tblMaterie values ('F001', 'Fizica', '3', 3, 2, 0, 0, 'N', 'E', 4)

select * from tblMaterie

update tblStudent set Grupa='10205' where NrLeg='102345'


update tblStudent set Grupa='10206' where NrLeg='102346'
update tblStudent set Grupa='10204' where NrLeg='102347'
update tblStudent set Grupa='10205' where NrLeg='102348'
update tblStudent set Grupa='10204' where NrLeg='102349'
update tblStudent set Grupa='10206' where NrLeg='102350'
update tblStudent set Grupa='10206' where NrLeg='102351'

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as Student,


NrTelefon,Interior,Observatii
from tblStudent as tb11, tblTelefonStud as tb12
where tb11.NrLeg=tb12.NrLeg
order by NumeStudent,PrenumeStudent,InitialaStudent,Observatii

select Grupa, NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti anul


II cu telefon],
NrTelefon,Interior,Observatii
from tblStudent as tb11, tblTelefonStud as tb12
where (tb11.NrLeg=tb12.NrLeg) and (Grupa like '102%')
order by NumeStudent,PrenumeStudent,InitialaStudent,Observatii

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti anul II cu


telefon],
NrTelefon,Interior,Observatii
from tblStudent as tb11 inner join tblTelefonStud as tb12
on (tb11.NrLeg=tb12.NrLeg) where (Grupa like '102%')
order by NumeStudent,PrenumeStudent,InitialaStudent,Observatii

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti cu telefon


mobil]
from tblStudent as tb11 inner join tblTelefonStud as tb12
on tb11.NrLeg=tb12.NrLeg
where Observatii='personal'
order by NumeStudent,PrenumeStudent,InitialaStudent,Observatii

select Grupa, count(*) as [Studenti cu telefon mobil]


from tblStudent as tb11 inner join tblTelefonStud as tb12
on tb11.NrLeg=tb12.NrLeg
group by Grupa
order by Grupa
select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti],
NrTelefon,Interior,Observatii
from tblStudent as tb11, tblTelefonStud as tb12
where tb11.NrLeg=tb12.NrLeg
order by NumeStudent,PrenumeStudent,InitialaStudent

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti],


ISNULL (NrTelefon,'') as NrTelefon,isnull (Interior,'') as Interior,isnull
(Observatii,'') as Observatii
from tblStudent as tb11, tblTelefonStud as tb12
where tb11.NrLeg=tb12.NrLeg
order by NumeStudent,PrenumeStudent,InitialaStudent

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti],


ISNULL (NrTelefon,'') as NrTelefon,isnull (Interior,'') as Interior,isnull
(Observatii,'') as Observatii
from tblStudent as tb11 left outer join tblTelefonStud as tb12
on tb11.NrLeg=tb12.NrLeg
order by NumeStudent,PrenumeStudent,InitialaStudent

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti],


NumeMaterie,Semestrul, Credit
from tblStudent as tb11, tblMaterie as tb12, tblStudiaza as tb13
where (tb11.NrLeg='102348') and
(tb11.NrLeg=tb13.NrLeg) and
(tb12.ID_Materie=tb13.ID_Materie)
order by Semestrul, NumeMaterie

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student],


NumeMaterie,Semestrul,Credit
from (tblStudent as tb11 inner join tblTelefonStud as tb13
on tb11.NrLeg=tb13.NrLeg) inner join tblMaterie as tb12
on tb12.ID_Materie=tb13.ID_Materie
where NrLeg='102348'
order by Semestrul, NumeMaterie

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student],


NumeMaterie,Semestrul,Credit
from tblStudent,tblMaterie

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student],


NumeMaterie,Semestrul,Credit
from tblStudent cross join tblMaterie

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student ACE],


from tblStudent
union all
select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student ELTH],
from tblStudentELTH

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student ACE+ELTH],


from tblStudent
union all
select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Student ELTH],
from tblStudentELTH

select NumeStudent+' '+InitialaStudent+' '+PrenumeStudent as [Studenti ACE+ELTH],


from (select NrLeg, NumeStudent, PrenumeStudent, InitialaStudent
from tblStudent
union
select NrLeg, NumeStudent,InitialaStudent,PrenumeStudent
from tblStudentELTH ) as t1
order by NumeStudent, PrenumeStudent,InitialaStudent

select t1.NumeStudent+''+t1.InitialaStudent+''+t1.PrenumeStudent as
[Studenti la ACE si ELTH]
from tblStudent as t1, tblStudentELTH as t2
where t1.NrLeg=t2.NrLeg

select t1.NumeStudent+''+t1.InitialaStudent+''+t1.PrenumeStudent as
[Studenti la ACE si ELTH]
from tblStudent as t1
where t1.NrLeg in
(select t2.NrLeg from tblStudentELTH as t2)

select t1.NumeStudent+''+t1.InitialaStudent+''+t1.PrenumeStudent as
[Studenti numai la ACE]
from tblStudent as t1
where t1.NrLeg not in
(select t2.NrLeg from tblStudentELTH as t2)

select * from tblStudent

select * from tblStudiaza

delete from tblStudent

select * from tblStudent

drop table tblStudiaza


drop table tblMaterie
drop table tblTelefonStud
drop table tblStudent
drop database dbSecretariat04_05

You might also like