Sunteți pe pagina 1din 4

Ministerul Educației, Culturii și Cercetării al Republicii Moldova

Universitatea Tehnică a Moldovei


Facultatea Calculatoare, Informatică și Microelectronică

Raport la
Lucrarea de laborator Nr. 4
Disciplina: Programarea orientata pe obiecte

Tema: ” Baze de date”

Au efectuat: Botnaru Alexandru

A verificat: Vadim Eladii

Chișinău – 2020
Obiectivele lucrării:
1. Descarcă și instalează un server de baza de date(mysql, postgres, etc)
2. Descarcă și instalează un client pentru baza de date(datagrip, workbench, pgAdmin 4, etc)
3. Conecteaza la server cu ajutorul la client
4. Creaza cel putin 3 tabele
5. Adăuga, modifica, șterge, selectează date din tabele(cel puțin câte 5 operații de fiecare)
6. Crearea unei legături între doua tablele(foreign key) si utilizarea la INNER JOIN, RIGHTJOIN,
LEFT JOIN, FULL JOIN cite doua selecturi de fiecare
create table universityInfo
(
universityId numeric primary key ,
universityName varchar(100) unique ,
nrStudents numeric not null ,
city varchar(50),
adress varchar(100)
);

INSERT INTO universities(universityId, universityName, nrStudents, city, adress)


VALUES (0001,'Universitatea Tehnica a Moldovei',3500,'Chisinau','str.Studentilor');

INSERT INTO universities(universityId, universityName, nrStudents, city, adress)


VALUES (0002,'Universitatea de Stat a Moldovei',3000,'Chisinau','str.Stefan cel Mare');

INSERT INTO universities(universityId, universityName, nrStudents, city, adress)


VALUES (0003,'Universitatea Agrara a Moldovei',2800,'Chisinau','str.Sfergsa');

INSERT INTO universities(universityId, universityName, nrStudents, city, adress)


VALUES (0004,'Universitatea Cooperatist-Comerciala',2000,'Chisinau','str.Deleanu');

INSERT INTO universities(universityId, universityName, nrStudents, city, adress)


VALUES (0005,'Academia de Studii Economice a Modlovei',3800,'Chisinau','str.Banulescu-
Bodoni');

INSERT INTO universities(universityId, universityName, nrStudents, city, adress)


VALUES (0006,'Universitatea Poli-Tehnica a
Romaniei',4200,'Bucuresti','str.Independentei');

SELECT * FROM universities;

SELECT universityId,universityName FROM universities WHERE city like 'B%';

UPDATE universities SET adress='str.Mircesti 42' where universityId=3;

ALTER TABLE universities add column country varchar(50);

UPDATE universities SET country='Republica Moldova ' WHERE city='Chisinau';

UPDATE universities SET country='Romania ' WHERE city='Bucuresti';

INSERT INTO universities(universityId, universityName, nrStudents, city, adress,country)


VALUES (0007,'Universitatea din Bucuresti',4800,'Bucuresti','str.Regina
Elizabeta','Romania');

create table students


(
studentId numeric primary key ,
name varchar(50),
surname varchar(50),
age numeric,
phoneNumber decimal,
grade decimal,
studentAdress varchar(50),
universityId numeric,
CONSTRAINT fk_universities FOREIGN KEY (universityId) REFERENCES
universities(universityId)
);

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,universityId)
VALUES(001,'Alexandru','Botnaru',20,0037368396468,7.80,'str.Balcani2/2',1);

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,universityId)
VALUES(002,'Ardovan','Vlad',20,00373589614,7.20,'str.Alba ulia',5);

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,universityId)
VALUES(003,'Grigore','Spanu',21,0040824369,8.30,'str.Independentei',7);

ALTER TABLE students add column country varchar(50);

UPDATE students SET country='Republica Moldova ' WHERE universityId < 6;

UPDATE students SET country='Romania ' WHERE universityId >= 6;

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,universityId,country)
VALUES(004,'Adrian','Gaibu',20,0040860349,7.90,'str.Mihai Eminescu',7,'Romania');

SELECT * FROM students;

UPDATE students SET phoneNumber = 408243698283 WHERE studentId = 3 ;


UPDATE students SET phoneNumber = 408083142093 WHERE studentId = 4 ;
UPDATE students SET phoneNumber = 37369456818 WHERE studentId = 2 ;

--joins
SELECT students.name,surname,studentId,universities.universityname FROM students
inner join universities
on students.universityId = universities.universityid;

SELECT students.name,surname,studentId,universities.universityname,universitycountry FROM


students
inner join universities
on students.universityId = universities.universityid;

SELECT students.name,students.surname,students.studentId,
universities.universityname,universities.universitycountry FROM students
full join universities
on students.universityId = universities.universityid;

SELECT students.name,students.surname,students.studentId,
universities.universityname,universities.universitycountry FROM students
left join universities
on students.universityId = universities.universityid;

SELECT students.name,students.surname,students.studentId,
universities.universityname,universities.universityid,universities.universitycountry FROM
students
right join universities
on students.universityId = universities.universityid;

SELECT students.name,students.surname,students.studentId,
universities.universityname,universities.universityid,universities.universitycountry FROM
students
inner join universities
on students.universityId = universities.universityid WHERE universitycountry like
'Romania';

SELECT students.name,students.surname,students.studentId,
universities.universityname,universities.universityid,universities.universitycountry FROM
students
full join universities
on students.universityId = universities.universityid WHERE universitycountry like
'Romania%';

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,universityId,country)
VALUES(5,'Mungiu','Andreea',22,0037369257618,8.70,'str.Stefan cel Mare',2,'Republica
Moldova');

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,universityId,country)
VALUES(6,'Istrati','Andrei',21,0037369281618,7.70,'str.Balcani',4,'Republica Moldova');

INSERT INTO students(studentId, name, surname, age, phoneNumber, grade,


studentAdress,country)
VALUES(7,'Guzun','Marcel',20,0037368436967,7.50,'str.Muncesit' ,'Republica Moldova');

ALTER TABLE universities rename column country to universityCountry;

CREATE TABLE teachers(


teacherid SERIAL primary key ,
name varchar(50) NOT NULL ,
surname varchar(50) NOT NULL ,
age numeric NOT NULL ,
object varchar(50),
email varchar(50),
universityId numeric ,constraint fk_university_teacher foreign key (universityId)
references universities(universityid)
);
INSERT INTO teachers(name, surname, age, object, email, universityId)
VALUES ('Bulhac','Ludmila',49,'fizica','bulhac.ludmila@gmail.com',3);

INSERT INTO teachers(name, surname, age, object, email, universityId)


VALUES ('Istrati','Veronica',44,'limba engleza','istrativeronica@gmail.com',3);

INSERT INTO teachers(name, surname, age, object, email, universityId)


VALUES ('Rusu','Vladimir',50,'matematica','rusuv@gmail.com',2);

INSERT INTO teachers(name, surname, age, object, email, universityId)


VALUES ('Munteanu','Anton',35,'programarea','munteanu.a@gmail.com',1);

SELECT teachers.name,surname,teacherid,
universities.universityname,universities.universityid,universities.universitycountry FROM
teachers
full join universities
on teachers.universityId = universities.universityid;

S-ar putea să vă placă și