How can I create a user in SQL Server Express database I added to my project?

John Egbert picture John Egbert · Sep 17, 2010 · Viewed 30k times · Source

How can I create a SQL user in a SQL Server Express database that I added to my project?

I need to create a user to use in a connection string that doesn't use Integrated Security.

Answer

Martin Smith picture Martin Smith · Sep 17, 2010

You would need to create a SQL Authenticated login first with CREATE LOGIN then add a user associated with that login to your database by using CREATE USER.

USE [master]
GO
CREATE LOGIN [JohnEgbert] WITH PASSWORD=N'YourPassword', 
                 DEFAULT_DATABASE=[YourDB], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [YourDB]
GO
CREATE USER [JohnEgbert] FOR LOGIN [JohnEgbert] WITH DEFAULT_SCHEMA=[dbo]
GO