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

Dynamic SQL Permissions Granting Script

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Dynamic SQL Permissions Granting Script

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DECLARE @Usuario NVARCHAR(50), @Permissao NVARCHAR(50);

DECLARE PermissaoCursor CURSOR FOR

SELECT Nome, Permissao FROM Contas;

OPEN PermissaoCursor;

FETCH NEXT FROM PermissaoCursor INTO @Usuario, @Permissao;

WHILE @@FETCH_STATUS = 0

BEGIN

IF @Permissao = 'SELECT'

BEGIN

GRANT SELECT ON Funcionarios TO @Usuario;

END

ELSE IF @Permissao = 'INSERT'

BEGIN

GRANT INSERT ON Funcionarios TO @Usuario;

END

ELSE IF @Permissao = 'UPDATE'

BEGIN

GRANT UPDATE ON Funcionarios TO @Usuario;

END

FETCH NEXT FROM PermissaoCursor INTO @Usuario, @Permissao;

END

CLOSE PermissaoCursor;

DEALLOCATE PermissaoCursor;

You might also like