如何为 SQL 服务器登录编写密码更改脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56923/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:20:04  来源:igfitidea点击:

How do I script a password change for a SQL server login?

sqlsql-serversql-server-2005

提问by Larry Foulkrod

Just what the title says, I need to change the password for an existing sql server login and I want to do it via sql script.

正如标题所说,我需要更改现有 sql server 登录名的密码,我想通过 sql 脚本来完成。

回答by Nagendra Mishr

If the user already has the ALTER ANY LOGIN permission (i.e. the user can change any password for any user) then this works:

如果用户已经拥有 ALTER ANY LOGIN 权限(即用户可以更改任何用户的任何密码),那么这有效:

alter login mylogin with password = 'mylogin'

Otherwise, if you don't want to make every user in your system a superuser, add a parameter of the old password for the same command:

否则,如果您不想让系统中的每个用户都成为超级用户,请为同一命令添加旧密码的参数:

alter login mylogin with password = 'mylogin' old_password='oldpassword'

回答by bkaid

alter login mylogin with password = 'mylogin'