Ejercicio 1
Ejercicio 1
declare
@existencia bit,
@tipo varchar(50),
@id int
open CursorExistencias
fetch next from CursorExistencias into @id,@existencia,@tipo
while (@@FETCH_STATUS = 0)
begin
if @existencia = 1
begin
if @tipo = 'Papeleria'
begin
update Productos set Cantidad_Exist = 100
where Id_Producto = @id;
end
else if @tipo = 'Electronica'
begin
update Productos set Cantidad_Exist = 250
where Id_Producto = @id;
end
else if @tipo = 'Ferreteria'
begin
update Productos set Cantidad_Exist = 150
where Id_Producto = @id;
end
else if @tipo = 'Informatica'
begin
update Productos set Cantidad_Exist = 210
where Id_Producto = @id;
end
else if @tipo = 'Serigrafia'
begin
update Productos set Cantidad_Exist = 175
where Id_Producto = @id;
end
else if @tipo = 'Drogueria'
begin
update Productos set Cantidad_Exist = 200
where Id_Producto = @id;
end
end
else
begin
if @tipo = 'Papeleria'
begin
update Productos set Cantidad_Exist = 10, Existencia = 1
where Id_Producto = @id;
end
else if @tipo = 'Electronica'
begin
update Productos set Cantidad_Exist = 25, Existencia = 1
where Id_Producto = @id;
end
else if @tipo = 'Ferreteria'
begin
update Productos set Cantidad_Exist = 15, Existencia = 1
where Id_Producto = @id;
end
else if @tipo = 'Informatica'
begin
update Productos set Cantidad_Exist = 20, Existencia = 1
where Id_Producto = @id;
end
else if @tipo = 'Serigrafia'
begin
update Productos set Cantidad_Exist = 15, Existencia = 1
where Id_Producto = @id;
end
else if @tipo = 'Drogueria'
begin
update Productos set Cantidad_Exist = 30, Existencia = 1
where Id_Producto = @id;
end
end
close CursorExistencias
deallocate CursorExistencias
4) Crear un procedimiento almacenado y dentro de este un Cursor que liste los
datos ordenados por grupos, se debe presentar de la siguiente forma (Titulo del
grupo seguido de cada producto con sus respectivos datos):
select * from Productos
AS
BEGIN
open CursorListarProductos
declare
@producto varchar(50),
@tipo varchar(50),
@proveedor varchar(50),
@observaciones varchar(100),
@cantidad int
print ''
fetch next from CursorProductos into @producto, @proveedor,
@observaciones, @cantidad
end
close CursorProductos
deallocate CursorProductos
print '---------------------------------------------------'
print '---------------------------------------------------'
fetch next from CursorListarProductos into @tipo
end
close CursorListarProductos
deallocate CursorListarProductos
END
execute SP_ListarProductos
5) Crear una Vista que retorne como parámetro de salida un top 10 de la tabla
creada ordenado por existencias
Id---Producto – Grupo—Proveedor – existencias
Ordenado de mayor a menor en Existencias
use master
if not exists (select name, type_desc from sys.server_principals where type = 'R'
and name ='Royers')
Begin
Create server role Royers authorization Estudiantes
End
go
go
Ejercicio 5: Modificar el Rol de Estudiantes y llamarlo ahora “Alumnos”
use master
go
sp_helpsrvrolemember sysadmin
go
Ejercicio 9: Crear un Inicio de Sesión con el semestre que cursa actualmente y
comprobar si existe y hacerlo miembro del rol de servidor Estudiantes
CREATE LOGIN [noveno semestre] with password = 'umg123'
use master
Alter server role Estudiantes add member [noveno semestre]
go
use master
Alter server role securityadmin add member Auditoria
go
sp_helpsrvrolemember securityadmin
go
USE Northwind