Created
March 18, 2019 09:43
-
-
Save mdnmdn/a565063ba77ff6d3ec541a7256f62a89 to your computer and use it in GitHub Desktop.
TSQL - Create user / enable mixed auth
This file contains 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 myUserName WITH PASSWORD = 'pwd'; | |
USE My_Database | |
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'myUserName') | |
BEGIN | |
CREATE USER [myUserName] FOR LOGIN [myUserName] | |
EXEC sp_addrolemember N'db_owner', N'myUserName' | |
END; | |
-- eventually enable mixed auth for sql server: | |
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', | |
N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment