Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 查找特定用户是db_所有者和db_数据编写器的数据库_Sql_Sql Server_Database - Fatal编程技术网

Sql 查找特定用户是db_所有者和db_数据编写器的数据库

Sql 查找特定用户是db_所有者和db_数据编写器的数据库,sql,sql-server,database,Sql,Sql Server,Database,我想创建一个查询,列出允许特定用户读写的所有数据库名称 我能够找到如何列出所有数据库的名称,但我不知道如何检查上述条件 SELECT name FROM master.sys.databases 如何检查是否允许特定用户在数据库中读写 以下是我想要的一个例子: I have 3 database : First,Second and Third. my users are Alex and John. Alex is allowed to write and read in the Firs

我想创建一个查询,列出允许特定用户读写的所有数据库名称

我能够找到如何列出所有数据库的名称,但我不知道如何检查上述条件

SELECT name
FROM master.sys.databases
如何检查是否允许特定用户在数据库中读写

以下是我想要的一个例子:

I have 3 database : First,Second and Third. my users are Alex and John. 
Alex is allowed to write and read in the First and Second database 
and John is allowed to write and read in the Second and the Third database.
What i want now, is to know in which databases Alex is allowed to write and read
and I need the name of the databases as result of the query 

此代码将使您能够在SQL Server上的所有数据库上查找所有者的sid和名称

SELECT *, owner_sid,suser_sname(owner_sid) as 'owner'
FROM master.sys.databases
然后获取您感兴趣的人的owner_sid,然后使用where子句作为示例运行

SELECT *, owner_sid,suser_sname(owner_sid) as 'owner'
FROM master.sys.databases
where owner_sid = 0x010500000000000515000000C34F142B1B2BCD5BE0276300E3B32200

db_datawriter角色提供对数据库中的表和视图的隐式访问,因此我不确定是否要恢复具有表的数据库,这些表的用户是db_datawriter?

这可能会有所帮助。如果有,你可以把它作为一个答案发布(在一段时间后)。这不是我真正需要的,我会给你一个例子:我有3个数据库:第一,第二,第三。我的用户是Alex和John。Alex可以在第一个和第二个数据库中写入和读取,John可以在第二个和第三个数据库中写入和读取。我现在想知道Alex可以在哪些数据库中写入和读取,我需要数据库的名称作为查询的结果