Skip to content

Instantly share code, notes, and snippets.

@jknsware
Last active May 15, 2020 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jknsware/b30f84e12a43632d4c7260620445fb4b to your computer and use it in GitHub Desktop.
Save jknsware/b30f84e12a43632d4c7260620445fb4b to your computer and use it in GitHub Desktop.

Login with admin access and create the user account.

1> CREATE LOGIN user_name WITH PASSWORD = 'password'

2> GO

Switch to the database.

1> USE database_name

2> GO

Changed database context to 'database_name'.

Add the user to the database.

1> CREATE USER user_name FOR LOGIN user_name

2> GO

Give the user readonly permissions.

1> EXEC sp_addrolemember 'db_datareader', 'user_name'

2> GO

https://dba.stackexchange.com/questions/170762/sqlcmd-new-login-user https://stackoverflow.com/questions/6688880/how-do-i-grant-read-access-for-a-user-to-a-database-in-sql-server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment