sql 創建某一用戶只能查詢訪問某些表或視圖

use Charges
GO
----------刪除-架構-角色-用戶-----------------------------------------------
DROP SCHEMA [YXUSER]
GO


DROP SCHEMA [YX_VIEW]
GO

DROP USER [YXUSER]
GO


DROP ROLE [YX_VIEW]
GO


DROP LOGIN [YXUSER]
GO


DROP VIEW [V_YX_StudentChargeDetailItem]
GO


DROP VIEW [V_YX_ChargeItem]

GO

--------------創建視圖--------------------

create view b
as
select  *
from a
GO



--建立登錄用戶:用戶名,密碼,數據庫
exec sp_addlogin 'YXUSER','View123456','Charges'


--創建角色golden
exec sp_addrole 'YX_VIEW'




--授予角色golden 對數據庫的select 權限
grant select on V_YX_ChargeItem to YX_VIEW
grant select on V_YX_StudentChargeDetailItem to YX_VIEW


--手動修改用戶屬性
EXEC sp_grantdbaccess 'YXUSER','YXUSER'
--添加newuser爲角色newrole的成員
EXEC sp_addrolemember 'YX_VIEW','YXUSER'
go


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章