1> VISÃO CODMATRICULA DE TODOS OS ALUNOS QUE CURSAM ' DANÇA'
create view exc1 as
select codmMatricula from matricula m
inner join turma t
on m.turma_idturma = t. idturma
inner join atividade a
on t.atividade_idatividade = a.idatividade
where a.nome = "dança"
-------------------------------------------------------------------------
2> VISAO PARA CONTABILIZAR TOTAL DE FALTAS POR TURMA
create view exrc 2 as
select count(*) as 'QTD DE FALTAS', matricula_turma_idturma
where presente = 0
group by matricula_turma_idturma
-----------------------------------------------------------------------------
3> VISAO PARA SELECIONAR O HORARIO DA TURMA, NOME DA ATIVIDADE, INSTRUTOR E DURACAO DE UMA AULA
create view EX3 as
select t.horario, a.nome as 'NOME ATIVIDADE', i.nome as 'NOME INSTRUTOR', t.duracao
from turma t
inner join atividade a on a.idatividade = t.atividade_idatividade
inner join instrutor i on i.idinstrutor = t.instrutor_idinstrutor
------------------------------------------------------------------------
4> PROCEDURE CADASTRAR ATIVIDADE - SEM REPETIR
Create procedure exerc4
@nome varchar(100)
as begin
Declare @aux int
set @aux = ( Select nome from atividade where nome = @nome)
if (@aux=0)
insert into atividade
values @nome
else print "erro"
-----------------------------------------------------------------------------
5> PROCEDURE procedimento para gerar relatorio (usando cursor)
create procedure ex5
as begin
declare aluno cursor static for select nome,peso,altura from aluno;
declare @nome varchar(40), @peso int, @altura float;
open aluno;
fetch next from aluno into @nome,@peso,@altura;
while @@FETCH_STATUS = 0
begin
print '<ALUNO>'
print char(9)+'<NOME>'+@nome+'</NOME>'
print char(9)+'<PESO>'+convert(varchar(4),@peso)+'</PESO>'
print char(9)+'<ALTURA>'+convert(varchar(4),@altura)+'</ALTURA>'
print '</ALUNO>'
fetch next from aluno into @nome,@peso,@altura;
end
close aluno;
deallocate aluno;
end
-----------------------------------------------------------------------------