views:

36

answers:

2

Hi,

How to use CREATE LOGIN statement on SQL Server 2005?

I was trying nearly everything, with commas, without them, with strings, without them etc.

CREATE LOGIN @loginame WITH PASSWORD = 'pass', DEFAULT_DATABASE='dbname' DEFAULT_LANGUAGE='us_english', CHECK_POLICY= OFF;

I always get below error:

Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

+1  A: 

Do u want this Create login to be dynamic? Because u say @loginname?

I tried this code and it works for me..

CREATE LOGIN test WITH PASSWORD = 'pass', DEFAULT_DATABASE = [enter database here] , DEFAULT_LANGUAGE = us_english, CHECK_POLICY= OFF;
Emerion
A: 

If you're running this in SSMS, you could use SQLCMD Mode (found under the Query menu) to script the variable for your login name.

:setvar LoginName "YourLoginName"

CREATE LOGIN $(LoginName) WITH PASSWORD = 'pass', DEFAULT_DATABASE='dbname' DEFAULT_LANGUAGE='us_english', CHECK_POLICY= OFF;
Joe Stefanelli