How to use the CREATE LOGIN sql statement?

2019-06-15 07:38发布

How to use the CREATE LOGIN statement on SQL Server 2005?

I've tried 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 this 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.

3条回答
趁早两清
2楼-- · 2019-06-15 07:58

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;
查看更多
再贱就再见
3楼-- · 2019-06-15 08:17

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;
查看更多
Ridiculous、
4楼-- · 2019-06-15 08:21

The best way is to use above statements but as a string, and then evaluete/exe this string as a command.

查看更多
登录 后发表回答