Issue
受制于公司策略,密码必须要有过期时间,但如果时间到了用户就可能会被锁,定时通知修改又很麻烦,所以想使用脚本定时修改为旧密码。但单独使用下面的语句修改sql用户的密码就会报错。
alter login [test] with password=N'1234' old_password=N'1234'
-- 错误: password failed validation. The password for the user is too recent to change.
Solution
可以迂回一下
alter login [test] with check_policy=off ,check_expiration=off;
alter login [test] with password=N'1234' old_password=N'1234';
alter login [test] with check_policy=on ,check_expiration=on;