下面的代码允许我通过使用查询在 sql server 中创建用户。它当前创建一个用户配置文件,但它允许用户访问服务器上的所有数据库。我只希望他们能够访问“TEST”数据库我将如何去做
CREATE LOGIN [SupportUser]
WITH PASSWORD=N'SupportUser',
DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
GO
下面的代码允许我通过使用查询在 sql server 中创建用户。它当前创建一个用户配置文件,但它允许用户访问服务器上的所有数据库。我只希望他们能够访问“TEST”数据库我将如何去做
CREATE LOGIN [SupportUser]
WITH PASSWORD=N'SupportUser',
DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
GO
CREATE LOGIN [SupportUser] WITH PASSWORD=N'SupportUser', DEFAULT_DATABASE=[MASTER],
CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [TEST]
GO
CREATE USER [SupportUser] FOR LOGIN [SupportUser]
GO
USE [TEST]
GO
EXEC sp_addrolemember N'db_datareader', N'SupportUser'
GO
USE [TEST]
GO
EXEC sp_addrolemember N'db_datawriter', N'SupportUser'
GO
USE [TEST]
GO
EXEC sp_addrolemember N'db_ddladmin', N'SupportUser'
GO
尝试这个。
CREATE LOGIN [SupportUser]
WITH PASSWORD=N'SupportUser',
DEFAULT_DATABASE=[master],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
GO
USE [TEST]
GO
CREATE USER [SupportUser] FOR LOGIN [SupportUser]
GO
use [TEST]
GO
GRANT SELECT ON [dbo].[myView] TO [SupportUser]
GO