Tuesday, April 1, 2014

Create a user for SQL Server authentication

First log into sql server using sql management studio or other relevant tool as an administrator.
Then use following command to create testuser in testdb database. You can ignore DEFAULT_DATABASE part as well if it is not working.

-- Create user for SQL Authentication
USE master
CREATE LOGIN testuser
    WITH PASSWORD = 'test#123',DEFAULT_DATABASE = testdb
GO

-- Creates a database user for the login created above.
USE testdb
CREATE USER testuser FOR LOGIN testuser
GO