Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Verify SQL Server Login and Login Settings

By Seth Delconte,

This script verifies that a specified login name:

- exists (creates it if it does not exist)

- has the correct password (resets it)

- is a member of the sysadmin login role (joins if not a member)


and checks that the database users that should be associated:

- exist (creates them if they do not exist)

- are mapped to the login with specified permissions


Adjust database name(s) in @db_str, adding database names if needed. These database names are the databases you want the script to check/associate with the login.

Adjust the login name and password using @login and @password.

Adjust the default database name using @default_db.

Adjust the owner of the databases using @db_owner (I recommend 'sa' or other sysadmin account so that you can be assured that the login properties can be edited easily later.

Adjust the database role membership using @db_role. You may change this setting and re-run the script for multiple database role memberships.

Adjust the server role membership using @srv_role. This can be used similarly to @db_role.

Total article views: 1653 | Views in the last 30 days: 2
Related Articles

DBgroup membership of a ADuser member of an ADgroup declared as DBuser

know group membership after change SQL logins for Windows logins


DB_Owner Database Role Membership Permission in SQL 2005

DB_Owner Database Role Membership Permission in SQL 2005


Deployment for ASP.NET User Membership Role Management

Questions related to deploying ASP.NET Membership Provider


Adjusting Model

This Friday Steve Jones looks at the topic of defaults and whether you use the model database to adj...


open existing database

can't open existing database

add role    
create login