by
1
7
3,164
0
Top 1% !
Popular
Famous
Tagged
Specified
Refined
OpenSource
Popularity: 4431st place
Architecturex86_64
DBMSMS SQL Server
Extension.sql
LanguageSQL
LicenseMIT_X11
OSWindows
Windows VersionWindows7

Create a complete user for SQL Server security

This is a useful script to correctly create a user able to access SQL Server instance with an SQL account.
Make sure to create the login and THEN the user!
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/11405/Create-a-complete-user-for-SQL-Server-se?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'MyLoginName') DROP USER [MyLoginName] GO IF EXISTS (SELECT * FROM sys.syslogins WHERE name = N'MyLoginName') BEGIN EXEC sp_change_users_login 'Auto_Fix', 'MyLoginName', NULL, 'mystrongpsw'; END ELSE BEGIN CREATE LOGIN [MyLoginName] WITH PASSWORD=N'mystrongpsw', DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF END CREATE USER [MyLoginName] FROM LOGIN [MyLoginName] GO
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus