如何使用 CREATE LOGIN sql 语句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3854694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use the CREATE LOGIN sql statement?
提问by truthseeker
How to use the CREATE LOGIN
statement on SQL Server 2005?
CREATE LOGIN
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.
关键字“with”附近的语法不正确。如果此语句是公用表表达式或 xmlnamespaces 子句,则前一条语句必须以分号结束。
采纳答案by truthseeker
The best way is to use above statements but as a string, and then evaluete/exe this string as a command.
最好的方法是使用上面的语句但是作为一个字符串,然后将此字符串作为命令进行评估/执行。
回答by Emerion
Do u want this Create login to be dynamic? Because u say @loginname?
你希望这个 Create 登录是动态的吗?因为你说@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;
回答by Joe Stefanelli
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.
如果您在 SSMS 中运行它,您可以使用SQLCMD 模式(在查询菜单下找到)为您的登录名编写变量脚本。
:setvar LoginName "YourLoginName"
CREATE LOGIN $(LoginName) WITH PASSWORD = 'pass', DEFAULT_DATABASE='dbname' DEFAULT_LANGUAGE='us_english', CHECK_POLICY= OFF;