如何将现有的 SQL Server 登录名连接到同名的现有 SQL Server 数据库用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3144380/
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 connect an existing SQL Server login to an existing SQL Server database user of same name
提问by jkelley
Is there a SQL Server command to connect a userof a single database to a loginfor the database server of the same name?
是否有 SQL Server 命令将单个数据库的用户连接到同名数据库服务器的登录名?
For example:
例如:
Database Server - Default Instance
Database: TestDBServer Login - TestUser
Existing user on TestDB - TestUser
数据库服务器 - 默认实例
数据库:TestDB服务器登录 - TestUser
TestDB 上的现有用户 - TestUser
If I try to make the TestUser
login a user of the TestDB
database, the "User, group, or role" already exists.
如果我尝试使TestUser
登录成为TestDB
数据库的用户,则“用户、组或角色”已经存在。
Does anybody know of an easy way to assign the DB userto the server login?
有人知道将数据库用户分配给服务器登录名的简单方法吗?
回答by gbn
The newway (SQL 2008 onwards) is to use ALTER USER
该新方法(SQL 2008年起)是使用ALTER USER
ALTER USER OrphanUser WITH LOGIN = correctedLoginName;
回答by Gratzy
I think it's sp_change_users_login
. It's been a little while, but I used to do that when detaching and reattaching databases.
我认为是sp_change_users_login
。已经有一段时间了,但我曾经在分离和重新附加数据库时这样做。
回答by joelt
I've used the sp_change_users_login
procedure to accomplish, I think, that scenario.
我已经使用该sp_change_users_login
程序来完成,我认为,那个场景。