我需要编写一个脚本来将一个特定的数据库角色从一个 SQL 服务器复制到另一个.
I need to make a script to copy one particular database role from one SQL server to another.
是否有一种简单的方法可以生成一个脚本来创建角色和所有角色权限?
Is there an easy way to generate a script that creates the role and all the role permissions?
您可以通过这样的脚本获得所需的内容:
You can get what you need with a script like this:
declare @RoleName varchar(50) = 'RoleName'
declare @Script varchar(max) = 'CREATE ROLE ' + @RoleName + char(13)
select @script = @script + 'GRANT ' + prm.permission_name + ' ON ' + OBJECT_NAME(major_id) + ' TO ' + rol.name + char(13) COLLATE Latin1_General_CI_AS
from sys.database_permissions prm
join sys.database_principals rol on
prm.grantee_principal_id = rol.principal_id
where rol.name = @RoleName
print @script
这篇关于如何编写 SQL 服务器数据库角色的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!