Skip to content

Instantly share code, notes, and snippets.

@phaniav
Created June 5, 2018 21:01
Show Gist options
  • Save phaniav/32beddf5daa88f84d5d1686cd44dbe96 to your computer and use it in GitHub Desktop.
Save phaniav/32beddf5daa88f84d5d1686cd44dbe96 to your computer and use it in GitHub Desktop.
Script to create a sql admin login user in T-SQL
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