How to create a User with a Password with sql query in sql server

Posted by Jitendrasoft09 under Sql Server on 6/26/2013 | Points: 10 | Views : 759 | Status : [Member] [MVP] | Replies : 4
Hi All,
I want to understand How to create a User with a Password with sql query in sql server, let me know if anybody knows.

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: Satyapriyanayak on: 6/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://msdn.microsoft.com/en-us/library/aa337562%28v=sql.105%29.aspx

If this post helps you mark it as answer
Thanks

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 9/6/2013 [Member] Starter | Points: 25

Up
0
Down
CREATE LOGIN MyNewUser WITH PASSWORD = '$$$$$$$$$'

hope this will help....

sriram

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Jitendra Kumar,

You can use the below Query for create a new database user with password in sql server 2005:-

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

Happy Coding.

If it helps you or directs U towards the solution, MARK IT AS ANSWER

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
sample Script to create DB as well as Login
USE master

GO
CREATE DATABASE DatabaseName
GO

-- Create Login
CREATE LOGIN LoginXXX
WITH PASSWORD=N'Jiten@123',
DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
GO

USE [DatabaseName]
GO
-- Create User and map with particular login
CREATE USER [LoginXXX] FOR LOGIN [LoginXXX] WITH DEFAULT_SCHEMA=[dbo]
GO
EXEC sp_addrolemember N'db_owner', N'JoeDB'
GO
EXEC sys.sp_addsrvrolemember @loginame = N'LoginXXX', @rolename = N'setupadmin'
GO
EXEC sys.sp_addsrvrolemember @loginame = N'LoginXXX', @rolename = N'processadmin'
GO


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response