SQL Server 2008:如何向用户名授予权限?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3998634/
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
SQL Server 2008: how do I grant privileges to a username?
提问by l--''''''---------''''''''''''
I need to be able to establish an ODBC connection through SQL Server authentication.
我需要能够通过 SQL Server 身份验证建立 ODBC 连接。
In SSMS how do I grant permission for a user to be able to have ALL RIGHTS on a specific database?
在 SSMS 中,我如何授予用户在特定数据库上拥有所有权限的权限?
is there a way to do this graphically with SSMS?
有没有办法用 SSMS 以图形方式执行此操作?
回答by marc_s
If you want to give your user all read permissions, you could use:
如果你想给你的用户所有读取权限,你可以使用:
EXEC sp_addrolemember N'db_datareader', N'your-user-name'
That adds the default db_datareaderrole (read permission on all tables) to that user.
这db_datareader将向该用户添加默认角色(对所有表的读取权限)。
There's also a db_datawriterrole - which gives your user all WRITE permissions (INSERT, UPDATE, DELETE) on all tables:
还有一个db_datawriter角色 - 它为您的用户提供对所有表的所有写入权限(插入、更新、删除):
EXEC sp_addrolemember N'db_datawriter', N'your-user-name'
If you need to be more granular, you can use the GRANTcommand:
如果需要更细化,可以使用以下GRANT命令:
GRANT SELECT, INSERT, UPDATE ON dbo.YourTable TO YourUserName
GRANT SELECT, INSERT ON dbo.YourTable2 TO YourUserName
GRANT SELECT, DELETE ON dbo.YourTable3 TO YourUserName
and so forth - you can granularly give SELECT, INSERT, UPDATE, DELETE permission on specific tables.
等等 - 您可以细粒度地授予特定表的 SELECT、INSERT、UPDATE、DELETE 权限。
This is all very well documented in the MSDN Books Online for SQL Server.
这在SQL Server的MSDN 联机丛书中都有很好的记录。
And yes, you can also do it graphically - in SSMS, go to your database, then Security > Users, right-click on that user you want to give permissions to, then Propertiesadn at the bottom you see "Database role memberships" where you can add the user to db roles.
是的,您也可以以图形方式进行操作 - 在 SSMS 中,转到您的数据库,然后Security > Users右键单击您要授予权限的用户,然后Properties在底部添加“数据库角色成员资格”,您可以在其中添加用户到数据库角色。


回答by Joe Stefanelli
If you really want them to have ALL rights:
如果您真的希望他们拥有所有权利:
use YourDatabase
go
exec sp_addrolemember 'db_owner', 'UserName'
go
回答by SQLMenace
Like the following. It will make the user database owner.
像下面这样。它将使用户数据库所有者。
EXEC sp_addrolemember N'db_owner', N'USerNAme'

