DB2創建視圖並授權給其他用戶


創建視圖並授權給其他用戶


可以在操作系統界面、或者DB2交互界面下進行數據庫操作

查看數據庫節點
[db2inst1@ELONEHR-DB ~]$ db2 list db directory

System Database Directory

Number of entries in the directory = 1

Database 1 entry:

Database alias = ELONEHR
Database name = ELONEHR
Local database directory = /hehrdta
Database release level = d.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =

[db2inst1@ELONEHR-DB ~]$ db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 9.7.7

You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd

For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.

To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.

For more detailed help, refer to the Online Reference Manual.


db2 => connect to ELONEHR

Database Connection Information

Database server = DB2/LINUXX8664 9.7.7
SQL authorization ID = DB2INST1
Local database alias = ELONEHR
數據庫有哪些schema
db2 => select name from sysibm.sysschemata

NAME
---------------------------------------------------------
DB2INST1
EHRREAD
NULLID
ORA
SQLJ
SYSCAT
SYSFUN
SYSIBM
SYSIBMADM
SYSIBMINTERNAL
SYSIBMTS
SYSPROC
SYSPUBLIC
SYSSTAT
SYSTOOLS
ELONEHR

16 record(s) selected.
創建視圖
db2 =>create view ELONEHR.V_TB_INF_EMPLOYEE_PART as select * from ELONEHR.TB_INF_EMPLOYEE_PART

查詢視圖
db2 =>select tabschema||tabname from syscat.tables where TYPE = 'V' and tabname='V_TB_INF_EMPLOYEE_PART'

將ELONEHR的視圖V_TB_INF_EMPLOYEE_PART賦權給EHRREAD
db2 => GRANT SELECT ON ELONEHR.V_TB_INF_EMPLOYEE_PART TO USER EHRREAD
DB20000I The SQL command completed successfully.

查詢數據庫表結構
db2 =>describe table tbname
db2 => describe table syscat.tabauth

查看數據庫用戶權限
db2 => select TABSCHEMA,TABNAME,SELECTAUTH from syscat.tabauth where GRANTEE='EHRREAD' and TABNAME='V_TB_INF_EMPLOYEE_PART'


特權信息存儲在七個系統編目視圖中:

SYSCAT.DBAUTH 數據庫特權
SYSCAT.COLAUTH 表和視圖列特權
SYSCAT.INDEXAUTH 索引特權
SYSCAT.PACKAGEAUTH 包特權
SYSCAT.SCHEMAAUTH 模式特權
SYSCAT.TABAUTH 表和視圖特權
SYSCAT.TBSPACEAUTH 表空間特權

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM