MSSQL: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
|||
Linha 1: | Linha 1: | ||
=Basic Commands= | =Basic Commands= | ||
Azure SQL | |||
<syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
-- Create LOGIN | -- Create LOGIN | ||
CREATE LOGIN readonlylogin WITH password='1231!#ASDF!a'; | CREATE LOGIN readonlylogin WITH password='1231!#ASDF!a'; | ||
GO | |||
-- Create USER | -- Create USER | ||
CREATE USER readonlyuser FROM LOGIN readonlylogin; | CREATE USER readonlyuser FROM LOGIN readonlylogin; | ||
GO | |||
-- ADD ROLE MEMBER | -- ADD ROLE MEMBER | ||
EXEC sp_addrolemember 'db_datareader', 'readonlyuser'; | EXEC sp_addrolemember 'db_datareader', 'readonlyuser'; | ||
GO | |||
-- OR | |||
ALTER ROLE [db_datareader] ADD MEMBER [readonlyuser]; | |||
GO | |||
-- CREATE USER WITHOUT LOGIN | -- CREATE USER WITHOUT LOGIN | ||
CREATE USER readonlyuser WITH PASSWORD = '1231!#ASDF!a'; | CREATE USER readonlyuser WITH PASSWORD = '1231!#ASDF!a'; | ||
GO | |||
-- GET ALL PERMISSIONS EXPLICITLY GRANTED OR DENIED | |||
SELECT DISTINCT pr.principal_id, pr.name, pr.type_desc, | |||
pr.authentication_type_desc, pe.state_desc, pe.permission_name | |||
FROM sys.database_principals AS pr | |||
JOIN sys.database_permissions AS pe | |||
ON pe.grantee_principal_id = pr.principal_id; | |||
GO | |||
</syntaxhighlight> | |||
=Docs= | =Docs= | ||
*[https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles?view=sql-server-ver15 Database-Level Roles] | *[https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles?view=sql-server-ver15 Database-Level Roles] | ||
*[https://azure.microsoft.com/pt-br/blog/adding-users-to-your-sql-azure-database/ Adding Users to Your SQL Azure Database] | *[https://azure.microsoft.com/pt-br/blog/adding-users-to-your-sql-azure-database/ Adding Users to Your SQL Azure Database] |
Edição das 12h54min de 18 de outubro de 2021
Basic Commands
Azure SQL
-- Create LOGIN
CREATE LOGIN readonlylogin WITH password='1231!#ASDF!a';
GO
-- Create USER
CREATE USER readonlyuser FROM LOGIN readonlylogin;
GO
-- ADD ROLE MEMBER
EXEC sp_addrolemember 'db_datareader', 'readonlyuser';
GO
-- OR
ALTER ROLE [db_datareader] ADD MEMBER [readonlyuser];
GO
-- CREATE USER WITHOUT LOGIN
CREATE USER readonlyuser WITH PASSWORD = '1231!#ASDF!a';
GO
-- GET ALL PERMISSIONS EXPLICITLY GRANTED OR DENIED
SELECT DISTINCT pr.principal_id, pr.name, pr.type_desc,
pr.authentication_type_desc, pe.state_desc, pe.permission_name
FROM sys.database_principals AS pr
JOIN sys.database_permissions AS pe
ON pe.grantee_principal_id = pr.principal_id;
GO