0% found this document useful (0 votes)
34 views3 pages

Update: - IS Null

The document makes several changes to tables in a university database: 1. It updates professor addresses and adds constraints to tables. 2. It adds new columns to store group leader and advisor IDs and populates these columns. 3. It increases grades of group leaders. 4. It creates a new professors table and migrates data to it. 5. It creates a schedule table and inserts initial data.

Uploaded by

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

Update: - IS Null

The document makes several changes to tables in a university database: 1. It updates professor addresses and adds constraints to tables. 2. It adds new columns to store group leader and advisor IDs and populates these columns. 3. It increases grades of group leaders. 4. It creates a new professors table and migrates data to it. 5. It creates a schedule table and inserts initial data.

Uploaded by

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

USE [universitatea]

GO
------------------------------------------punctul-1
UPDATE dbo.profesori
SET Adresa_Postala_Profesor = 'mun. Chisinau' WHERE Adresa_Postala_Profesor IS NULL

-------------------------------------------punctul-2
ALTER TABLE dbo.grupe
ADD CONSTRAINT unique_Cod_Grupa UNIQUE(Cod_Grupa);
GO

ALTER TABLE dbo.grupe


ALTER COLUMN Cod_Grupa CHAR(6) NOT NULL;
GO

---------------------------------punctul-3

ALTER TABLE dbo.grupe


ADD Sef_Grupa INT,
Prof_Indrumator INT;
GO

----------------------------------a
UPDATE grupe SET Sef_Grupa = ( SELECT Sef_Grupa FROM(
SELECT Id_Grupa, MIN(Id_Student) Sef_Grupa, MAX(Med) AS Nota_Max FROM
(SELECT Id_Student, Id_Grupa, AVG(Nota) AS Med FROM studenti_reusita GROUP BY Id_Student,
Id_Grupa) AS rel1
GROUP BY Id_Grupa) AS rel2
WHERE grupe.Id_Grupa=rel2.Id_Grupa);

-----------------------------------b
UPDATE grupe
SET grupe.Prof_Indrumator = (SELECT TOP(1) Id_Profesor
FROM studenti_reusita
WHERE studenti_reusita.Id_Grupa = grupe.Id_Grupa
GROUP BY Id_Profesor
ORDER BY COUNT(Id_Disciplina) DESC, Id_Profesor DESC)

ALTER TABLE grupe


ADD CONSTRAINT valoare_unica UNIQUE (Prof_Indrumator)

-----------------------------------punctul-4
UPDATE dbo.studenti_reusita SET Nota = Nota + 1 WHERE Id_Student IN
(SELECT Sef_Grupa FROM dbo.grupe WHERE Id_Student=Sef_Grupa) AND Nota < 10;

-----------------------------------punctul-5
CREATE TABLE profesori_new(
Id_Profesor int NOT NULL PRIMARY KEY,
Nume_Profesor NVARCHAR(60) NOT NULL,
Prenume_Profesor NVARCHAR(60) NOT NULL,
Localitate NVARCHAR(60) DEFAULT 'mun. Chisinau',
Adresa_1 NVARCHAR(60) NOT NULL,
Adresa_2 NVARCHAR(60) NOT NULL
);
GO

INSERT into profesori_new(Id_Profesor, Nume_Profesor, Prenume_Profesor, Localitate, Adresa_1,


Adresa_2)
SELECT Id_profesor ,Nume_profesor , Prenume_profesor
,Coalesce(nullif(l.N,''),'mun. Chisinau') Localitatea
,LTRIM(a1.N) Adresa_1
,LTRIM(a2.N) Adresa_2
FROM profesori
CROSS APPLY (SELECT COALESCE(NULLIF(CHARINDEX(', bd.',
isnull(adresa_postala_profesor,'')),0),
NULLIF(CHARINDEX(', str.',isnull(adresa_postala_profesor,'')),0),
LEN(isnull(adresa_postala_profesor,''))+1) AS p) s1
CROSS APPLY (SELECT ISNULL(NULLIF(CHARINDEX(',',isnull(adresa_postala_profesor,''),
s1.p+1),0),LEN(isnull(adresa_postala_profesor,''))+1) AS p) s2
CROSS APPLY (SELECT SUBSTRING(isnull(adresa_postala_profesor,''),1,ABS(s1.p-1)) AS N)l
CROSS APPLY (SELECT SUBSTRING(isnull(adresa_postala_profesor,''),s1.p+1,ABS(s2.p-s1.p-1)) AS N)
a1
CROSS APPLY (SELECT
SUBSTRING(isnull(adresa_postala_profesor,''),s2.p+1,LEN(isnull(adresa_postala_profesor,''))) AS
N) a2

----------------------------------------punctul-6
CREATE TABLE orarul (
Id_Disciplina INT NOT NULL,
Id_Profesor INT,
Id_Grupa SMALLINT,
Zi CHAR(2),
Ora TIME,
Auditoriu INT,
Bloc CHAR(1) NOT NULL DEFAULT('B'),
PRIMARY KEY (Id_Grupa, Zi, Ora));

INSERT INTO dbo.orarul (Id_Disciplina, Id_Profesor, Id_Grupa, Zi, Ora, Auditoriu) VALUES
(107, 101, 1, 'Lu','08:00', 202),
(108, 101, 1, 'Lu','11:30', 501),
(109, 117, 1, 'Lu','13:00', 501);

----------------------------------------punctul-7

INSERT INTO orarul (Id_Disciplina, Id_Profesor, Id_Grupa, Zi, Ora)


values ((select Id_Disciplina from discipline where Disciplina = 'Structuri de date si
algoritmi'),
(select Id_Profesor from profesori where Nume_Profesor = 'Bivol' and Prenume_Profesor
= 'Ion'),
(select Id_Grupa from grupe where Cod_Grupa = 'INF171'),
'Lu', '08:00')
INSERT INTO orarul (Id_Disciplina, Id_Profesor, Id_Grupa, Zi, Ora)
values ((select Id_Disciplina from discipline where Disciplina = 'Programe aplicative'),
(select Id_Profesor from profesori where Nume_Profesor = 'Mircea' and
Prenume_Profesor = 'Sorin'),
(select Id_Grupa from grupe where Cod_Grupa = 'INF171'),
'Lu', '11:30')

INSERT INTO orarul (Id_Disciplina, Id_Profesor, Id_Grupa, Zi, Ora)


values ((select Id_Disciplina from discipline where Disciplina = 'Baze de date'),
(select Id_Profesor from profesori where Nume_Profesor = 'Micu' and
Prenume_Profesor = 'Elena'),
(select Id_Grupa from grupe where Cod_Grupa = 'INF171'),
'Lu', '13:00')

You might also like