限制 SQL Server 登录只能访问一个数据库

发布于 2024-09-30 13:51:55 字数 164 浏览 0 评论 0原文

我有一个 SQL Server 服务器,上面有大约 50 个数据库。

我希望为希望访问其数据库的客户创建一个新的Login

但我不想让他们访问其他 49 个数据库

我该怎么做?

I have a SQL Server server which has around 50 databases on it.

I wish to create a new Login for a client who wishes to have access to their database.

But I don't want to give them access to the other 49 databases.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

§普罗旺斯的薰衣草 2024-10-07 13:51:55

我认为这是我们非常喜欢做的事情。

--Step 1: (create a new user)
create LOGIN hello WITH PASSWORD='foo', CHECK_POLICY = OFF;


-- Step 2:(deny view to any database)
USE master;
GO
DENY VIEW ANY DATABASE TO hello; 


 -- step 3 (then authorized the user for that specific database , you have to use the  master by doing use master as below)
USE master;
GO
ALTER AUTHORIZATION ON DATABASE::yourDB TO hello;
GO

如果您之前已经创建了用户并分配给该数据库,

USE [yourDB] 
CREATE USER hello FOR LOGIN hello WITH DEFAULT_SCHEMA=[dbo] 
GO

请通过执行以下操作将其删除并按照以下步骤

   USE yourDB;
   GO
   DROP USER newlogin;
   GO

操作有关更多信息,请点击链接:

隐藏 Microsoft Sql Server 2008R2 及更高版本上的登录数据库

I think this is what we like to do very much.

--Step 1: (create a new user)
create LOGIN hello WITH PASSWORD='foo', CHECK_POLICY = OFF;


-- Step 2:(deny view to any database)
USE master;
GO
DENY VIEW ANY DATABASE TO hello; 


 -- step 3 (then authorized the user for that specific database , you have to use the  master by doing use master as below)
USE master;
GO
ALTER AUTHORIZATION ON DATABASE::yourDB TO hello;
GO

If you already created a user and assigned to that database before by doing

USE [yourDB] 
CREATE USER hello FOR LOGIN hello WITH DEFAULT_SCHEMA=[dbo] 
GO

then kindly delete it by doing below and follow the steps

   USE yourDB;
   GO
   DROP USER newlogin;
   GO

For more information please follow the links:

Hiding databases for a login on Microsoft Sql Server 2008R2 and above

极度宠爱 2024-10-07 13:51:55
  1. 使用 Management Studio
  2. Goto Security 连接到您的 SQL Server 实例 ->登录-> (右键单击)新登录
  3. 填写用户详细信息
  4. 在用户映射下,选择您希望用户能够访问和配置的数据库

更新:

您还需要转到安全 -> ;服务器角色,对于公共,检查TSQL默认TCP/TSQL默认VIA/TSQL本地计算机/TSQL命名管道的权限并删除连接 权限

  1. Connect to your SQL server instance using management studio
  2. Goto Security -> Logins -> (RIGHT CLICK) New Login
  3. fill in user details
  4. Under User Mapping, select the databases you want the user to be able to access and configure

UPDATE:

You'll also want to goto Security -> Server Roles, and for public check the permissions for TSQL Default TCP/TSQL Default VIA/TSQL Local Machine/TSQL Named Pipesand remove the connect permission

池木 2024-10-07 13:51:55

这是为了补充被选为正确答案的内容。它缺少一个步骤,如果不完成,用户仍然可以访问数据库的其余部分。
首先,按照@DineshDB 的建议执行

  1. Connect to your SQL server instance using management studio
   2. Goto Security -> Logins -> (RIGHT CLICK) New Login
   3. fill in user details
   4. Under User Mapping, select the databases you want the user to be able to access and configure

以下缺少的步骤:

5. Under user mapping, ensure that "sysadmin" is NOT CHECKED and select "db_owner" as the role for the new user.

就是这样。

this is to topup to what was selected as the correct answer. It has one missing step that when not done, the user will still be able to access the rest of the database.
First, do as @DineshDB suggested

  1. Connect to your SQL server instance using management studio
   2. Goto Security -> Logins -> (RIGHT CLICK) New Login
   3. fill in user details
   4. Under User Mapping, select the databases you want the user to be able to access and configure

the missing step is below:

5. Under user mapping, ensure that "sysadmin" is NOT CHECKED and select "db_owner" as the role for the new user.

And thats it.

彩扇题诗 2024-10-07 13:51:55

对于其他想知道如何执行此操作的人,我为 SQL Server 2008 R2 及更高版本提供了以下解决方案:

USE master
go
DENY VIEW ANY DATABASE TO [user]
go

这将完全满足上述要求。

For anyone else out there wondering how to do this, I have the following solution for SQL Server 2008 R2 and later:

USE master
go
DENY VIEW ANY DATABASE TO [user]
go

This will address exactly the requirement outlined above..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文