Created
June 5, 2018 21:01
-
-
Save phaniav/32beddf5daa88f84d5d1686cd44dbe96 to your computer and use it in GitHub Desktop.
Script to create a sql admin login user in T-SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE LOGIN NewAdminName WITH PASSWORD = 'ABCD' | |
GO | |
--Here is how you create a User with db_owner privileges using the Login you just declared: | |
Use YourDatabase; | |
GO | |
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'NewAdminName') | |
BEGIN | |
CREATE USER [NewAdminName] FOR LOGIN [NewAdminName] | |
EXEC sp_addrolemember N'db_owner', N'NewAdminName' | |
END; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment