Deploying a Database - SQL Server

When deploying a SQL Server database for the first time, in addition to distributing the BAK file, you will probably need to create the user and login used by the connection string in your configuration file(s). The following script will do this.

USE [master]
GO
CREATE LOGIN [MyUser] WITH PASSWORD=N'MyPassword', DEFAULT_DATABASE=[master], 
    CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [MyDatabase]
GO
exec sp_change_users_login @Action='Update_One', @UserNamePattern = 'MyUser', @LoginName ='MyUser'
GO