在哪种数据库软件/语言中,我们可以拥有一个可供多个用户访问的数据库,除了它的两列只能由管理员用户访问之外

发布于 2024-08-09 17:54:29 字数 65 浏览 11 评论 0原文

使用哪种数据库软件/语言可以创建可供多个用户访问的数据库,但其两列只能由管理员用户访问。请详细说明如何创建该数据库。

in which database software / language is it possible to create a database accessible by multiple users except its two columns to be accessed only by admin user. please give details how this database can be created.

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

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

发布评论

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

评论(3

瀞厅☆埖开 2024-08-16 17:54:29

下面是一个使用视图控制访问来屏蔽对数据库中某些列的访问的示例(来自Oracle)。请注意,我们可以进一步限制哪些列可以更新。

SQL> conn apc/apc
Connected.
SQL> desc emp
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPNO                                     NOT NULL NUMBER(4)
 ENAME                                     NOT NULL VARCHAR2(10)
 JOB                                                VARCHAR2(9)
 MGR                                                NUMBER(4)
 HIREDATE                                           DATE
 SAL                                                NUMBER(7,2)
 COMM                                               NUMBER(7,2)
 DEPTNO                                             NUMBER(2)

SQL> create or replace view v_emp as
  2  select empno, ename, job, mgr, hiredate, deptno from emp
  3  /

View created.

SQL> grant select, insert, update (job, mgr, deptno) on v_emp to a
  2  /

Grant succeeded.

SQL> conn a/a
Connected.
SQL> create synonym emp for apc.v_emp
  2  /

Synonym created.

SQL> select * from emp where deptno = 10
  2  /

     EMPNO ENAME      JOB              MGR HIREDATE      DEPTNO
---------- ---------- --------- ---------- --------- ----------
      7782 BOEHMER    MANAGER         7839 09-JUN-81         10
      7839 SCHNEIDER  PRESIDENT            17-NOV-81         10
      7934 KISHORE    CLERK           7782 23-JAN-82         10

SQL> update emp set deptno = 40 where empno = 7934
  2  /

1 row updated.

SQL> insert into emp values (8000, 'APC', 'DOGSBODY', 7934, sysdate, 40)
  2  /

1 row created.

SQL> update emp set hiredate = sysdate-720 where empno = 7934
  2  /
update emp set hiredate = sysdate-720 where empno = 7934
       *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> delete from emp where empno = 7934
  2  /
delete from emp where empno = 7934
            *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL>

这是一个相对简单的示例,因为视图与表是一对一的,并且屏蔽列是可选的。如果屏蔽列已定义为 NOT NULL,那么我需要一个 INSTEAD OF 触发器来默认或派生 INSERT 上的值(否则我将不得不放弃 INSERT 权限)。

Here is an example (from Oracle) of using a view to control access to shield access to some columns in a database. Note that we can further restrict which columns can be updated.

SQL> conn apc/apc
Connected.
SQL> desc emp
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 EMPNO                                     NOT NULL NUMBER(4)
 ENAME                                     NOT NULL VARCHAR2(10)
 JOB                                                VARCHAR2(9)
 MGR                                                NUMBER(4)
 HIREDATE                                           DATE
 SAL                                                NUMBER(7,2)
 COMM                                               NUMBER(7,2)
 DEPTNO                                             NUMBER(2)

SQL> create or replace view v_emp as
  2  select empno, ename, job, mgr, hiredate, deptno from emp
  3  /

View created.

SQL> grant select, insert, update (job, mgr, deptno) on v_emp to a
  2  /

Grant succeeded.

SQL> conn a/a
Connected.
SQL> create synonym emp for apc.v_emp
  2  /

Synonym created.

SQL> select * from emp where deptno = 10
  2  /

     EMPNO ENAME      JOB              MGR HIREDATE      DEPTNO
---------- ---------- --------- ---------- --------- ----------
      7782 BOEHMER    MANAGER         7839 09-JUN-81         10
      7839 SCHNEIDER  PRESIDENT            17-NOV-81         10
      7934 KISHORE    CLERK           7782 23-JAN-82         10

SQL> update emp set deptno = 40 where empno = 7934
  2  /

1 row updated.

SQL> insert into emp values (8000, 'APC', 'DOGSBODY', 7934, sysdate, 40)
  2  /

1 row created.

SQL> update emp set hiredate = sysdate-720 where empno = 7934
  2  /
update emp set hiredate = sysdate-720 where empno = 7934
       *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> delete from emp where empno = 7934
  2  /
delete from emp where empno = 7934
            *
ERROR at line 1:
ORA-01031: insufficient privileges


SQL>

This is a relatively straightforward example because the view is one-to-one with the table and the shielded columns are optional.; If the shielded columns had been defined as NOT NULL then I would need an INSTEAD OF trigger to default or derive values on INSERT (or I would have to withold the INSERT privilege).

旧时模样 2024-08-16 17:54:29

Oracle 可以使用视图来做到这一点,但更“正确”的方法是使用具有列屏蔽行为的列级虚拟专用数据库,其中敏感列对非特权用户显示为空。

Oracle can do this using views, but the more "proper" way would be to use Column-Level Virtual Private Database with column-masking behavior, in which sensitive columns appear as null to non-privileged users.

扛刀软妹 2024-08-16 17:54:29

在大多数 DBMS(例如 Oracle、Mysql、SQL Server...)中,您可以授予用户对您想要的任何列的访问权限或撤销任何权限。

In most DBMS like (Oracle, Mysql, SQL server...) you can grant users access to any column you want or revoke any permission.

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