0% found this document useful (0 votes)
28 views1 page

Advsql

The document describes creating a stored procedure in MySQL called "descriereStudenti" that takes in student information like name, student ID, faculty, and year and inserts records for that student into multiple tables. It returns the number of courses the student is enrolled in. The procedure is called at the end on a sample student to return their course count.

Uploaded by

Roby Anton
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)
28 views1 page

Advsql

The document describes creating a stored procedure in MySQL called "descriereStudenti" that takes in student information like name, student ID, faculty, and year and inserts records for that student into multiple tables. It returns the number of courses the student is enrolled in. The procedure is called at the end on a sample student to return their course count.

Uploaded by

Roby Anton
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/ 1

\!

cls

use lefti_antonrobert;

drop table if exists cursuri, studentiCursuri, studenti, cursuriFacultati,


facultati, studentiFacultati, tutoriCursuri, tutoriFacultati, departamente, tutori,
salarii;

source C:\Users\stud\Robert_Anton_1_1\universitate.sql
show full tables;
/*
create or replace view departamenteFacultati
as select numeFacultate, group_concat(numeDepartament) as listaDepartamente,
count(idDepartament) as numarDepartament
from facultati f left join departamente d using(idFacultate)
group by f.idFacultate;

select * from departamenteFacultati;


*/

drop procedure if exists descriereStudenti;


delimiter |
create procedure descriereStudenti(in facultate varchar(50), in student
varchar(50), in matricol varchar(10), in an INT, out numarCursuri INT)
begin
declare idS int DEFAULT NULL;
declare idF int DEFAULT NULL;
INSERT INTO studenti set numeStudent = student;
select LAST_INSERT_ID() INTO idS;
select idFacultate INTO idF FROM facultati WHERE numeFacultate = facultate;
IF idS IS NOT NULL AND idF IS NOT NULL THEN
INSERT INTO studentiFacultati(idFacultate, idStudent, matricolStudent,
anScolarStudent) VALUES (idF, idS, matricol, an);
INSERT INTO studentiCursuri(idCurs, idStudent) SELECT idCurs, idS from
numeFacultate WHERE idFacultate = idF and anScolarCurs = an;
SELECT COUNT(idCurs) INTO numarCursuri FROM studenti s INNER JOIN
studentiCursuri USING(idStudent) WHERE s.idStudent = idS;
END IF;
end |
delimiter ;

call descriereStudenti('etc', 'anton robert', 'lk8679', 2, @numarCursuri);


select @numarCursuri;

You might also like