Skip to content

Instantly share code, notes, and snippets.

@mdnmdn
Created March 18, 2019 09:43
Show Gist options
  • Save mdnmdn/a565063ba77ff6d3ec541a7256f62a89 to your computer and use it in GitHub Desktop.
Save mdnmdn/a565063ba77ff6d3ec541a7256f62a89 to your computer and use it in GitHub Desktop.
TSQL - Create user / enable mixed auth
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