Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new db user in SQL Server 2005

how do you create a new database user with password in sql server 2005?

i will need this user/password to use in the connection string eg:

uid=*user*;pwd=*password*;
like image 816
raklos Avatar asked Mar 20 '09 16:03

raklos


People also ask

How do I add a user to a database?

Expand the database in which to create the new database user. Right-click the Security folder, point to New, and select User.... In the Database User - New dialog box, on the General page, select one of the following user types from the User type list: SQL user with login.


1 Answers

CREATE LOGIN [user] WITH PASSWORD='password', 
       DEFAULT_DATABASE=[your_db], CHECK_POLICY=OFF
GO

CREATE USER [user] FOR LOGIN [user]
EXEC sp_addrolemember N'db_datareader', N'your_db'
EXEC sp_addrolemember N'db_datawriter', N'your_db'
GO

Where CHECK_POLICY=OFF switches off password complexity check, etc

like image 161
abatishchev Avatar answered Sep 30 '22 18:09

abatishchev