



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




Per visualizzare anche chi non era compreso nelle specialità
Per visualizzare n° specialità> select count(Medici_Specialità.Id_Specialità) as 'Numero_specialità', Medici_Specialità.Matricola, Medici.Nome, Medici.Cognome from Medici, Medici_Specialità where Medici.Matricola=Medici_Specialità.Matricola group by Medici_Specialità.matricola, Medici.Nome, Medici.Cognome having count(medici_specialità.id_specialità)> 1 order by Medici_Specialità.matricola Esercizi sulle stored procedure
@PIN int AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; if not exists (Select * From Pazienti Where PIN = @PIN) Begin Return 10 -- il paziente richiesto non esiste End -- Insert statements for procedure here Delete Pazienti Where PIN = @PIN END Modifica medico (esame) CREATE PROCEDURE Modifica_Medico -- Add the parameters for the stored procedure here @Matricola int, @Nome varchar( 50 ), @Cognome varchar( 50 ), @Data_Nascita date AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; if not exists (select *from Medici where Matricola=@Matricola) Begin Return 10 -- il medico è già presente end if exists (select *from Medici where Nome=@Nome and Matricola < > @Matricola) begin return 20 -- la matricola inserita è già presente in un altro record end -- Insert statements for procedure here update Medici Set @Matricola=Matricola, @Nome=Nome, @Cognome=Cognome, @Data_Nascita=Data_Nascita Where Matricola=@Matricola Return 1 -- Modifica effettuata correttamente END GO INSERIRE MEDICO CREATE PROCEDURE Inserisci_Medico -- Add the parameters for the stored procedure here @Nome varchar( 50 ), @Cognome varchar( 50 ), @Data_Nascita date, @Luogo_Nascita varchar( 50 ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; if exists (select *from Medici where Nome=@Nome and Cognome=@Cognome) Begin Return 10 -- Il medico è già presente end declare @Matricola int = null
select @Matricola=max(Matricola) from Medici if @matricola is null begin set @matricola= 0 end set @matricola=@matricola+ 1 -- Insert statements for procedure here insert into Medici (Matricola, Nome, Cognome, Data_Nascita, Luogo_Nascita) Values (@Matricola, @Nome, @Cognome, @Data_Nascita, @Luogo_Nascita) return 1 -- medico inserito correttamente END GO
CREATE PROCEDURE Elimina_Medico -- Add the parameters for the stored procedure here @Matricola int AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; if not exists (Select *from Medici where Matricola=@Matricola) begin return 10 -- il medico richiesto non esiste end -- Insert statements for procedure here Delete Medici where Matricola=@Matricola END GO
SELECT Regione_Nascita, COUNT(Regione_Nascita) AS 'Numero di persone nate nella regione' FROM Persona WHERE Regione_Nascita IS NOT NULL GROUP BY Regione_Nascita HAVING COUNT(*) > 150 ORDER BY Regione_Nascita