MSSQL

De Wiki Clusterlab.com.br
Revisão de 12h55min de 18 de outubro de 2021 por Damato (discussão | contribs) (→‎Docs)
Ir para navegação Ir para pesquisar

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

Docs