使用视图控制用户对数据访问

来源:互联网 发布:线性时间选择算法 编辑:程序博客网 时间:2024/05/17 16:12
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

问:我的Microsoft Access 2000应用程序由后端的SQL Server 2000数据库写入数据。为防止Access的用户看到SQL Server 2000表中的全部数据,我想使用一种只允许用户浏览授权数据行的视图。可以创建一种限制用户访问SQL Server数据的视图吗?

答:可以。如果每位用户以唯一的用户ID登录到Access,您就可以创建一种限制用户访问SQL Server数据的视图。以下的示例语句就可以创建这样一种视图:

CREATE VIEW v_data AS
  SELECT <column_list>
     FROM dbo.mytable AS a
     INNER JOIN dbo.authtable AS b
     ON (a.Pkey = b.DataKey
AND b.userid = suser_sname())

该视图按userid限制用户的访问权。它要求您保存一份与数据表(mytable)中特定主键相匹配的用户名的表(authtable)。如果您的情况相对比较简单——您无需管理多个用户的行访问权,则您可以将userid列插入到数据表中,如下列代码所示:

CREATE VIEW v_data AS
  SELECT <column_list>
    FROM dbo.mytable AS a
    WHERE a.userid = suser_sname()

—Microsoft SQL Server 开发团队
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击