Tuesday, 19 April 2016

Create DB user and assign role to user

-------------------------------------
-------DB User ----------------------

--sp_addlogin Creates a new SQL Server login that allows a user to connect to an instance of SQL Server by using SQL Server authentication.
-- EXEC sp_addlogin 'login name', 'Password', 'Database'
EXEC sp_addlogin 'dentry','dentry','doris'

----online Database Name------
use doris

--sp_adduser Adds a new user to the current database.
--EXEC sp_adduser 'login name', 'User name'
EXEC sp_adduser 'dentry','dentry'

--sp_addrolemember Adds a database user, database role, Windows login, or Windows group to a database role in the current database.
--EXEC sp_addrolemember 'DB role', 'User'
EXEC sp_addrolemember 'operator','dentry'

print 'user data entry created successfully'



--add new role in db

EXEC sp_addrole 'Managers'

No comments:

Post a Comment

SQL Table : Change Row As Column and Group Them... ( Setting column values as column names in the SQL query result )

Setting column values as column names in the SQL query result Problem Statement : id col1 col2 1 Pending 30 1 Resolved 48 ...