Home > Database > Mysql Tutorial > 使用视图控制用户对数据访问_MySQL

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 14:05:34
Original
1265 people have browsed it

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

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

CREATE VIEW v_data AS
SELECT
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
FROM dbo.mytable AS a
WHERE a.userid = suser_sname()

—Microsoft SQL Server 开发团队

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template