查看Teradata数据库用户对于表的操作权限
通过dbc.allrights表中的UserName列,DatabaseName列,TableName列和AccessRight列的查询可以获取指定用于对于指定数据库中指定表的操作权限。可用于在执行某条SQL语句之前,判定当前用户是否有执行此语句的权限,在权限不足时还可以尝试自动授权(不太安全,执行完应当revoke)等措施。
www.zzzyk.com
AccessRight列缩写词对应列表(共40个):
AccessRight 含义
AF ALTER FUNCTION
AP ALTER PROCEDURE
AS ABORT SESSION
CD CREATE DATABASE
CF CREATE FUNCTION
CG CREATE TRIGGER
CM CREATE MACRO
CO CREATE PROFILE
CP CHECKPOINT
CR CREATE ROLE
CT CREATE TABLE
CU CREATE USER
CV CREATE VIEW
D DELETE
DD DROP DATABASE
DF DROP FUNCTION
DG DROP TRIGGER
DM DROP MACRO
DO DROP PROFILE
DP DUMP
DR DROP ROLE
DT DROP TABLE
DU DROP USER
DV DROP VIEW
E EXECUTE
EF EXECUTE FUNCTION
I INSERT
IX INDEX
MR MONITOR RESOURCE
MS MONITOR SESSION
PC CREATE PROCEDURE
PD DROP PROCEDURE
PE EXECUTE PROCEDURE
RO REPLICATION OVERRIDE
R RETRIEVE/SELECT
RF REFERENCE
RS RESTORE
SS SET SESSION RATE
SR SET RESOURCE RATE
U UPDATE
示例SQL语句: www.zzzyk.com
[sql]
select username, databasename, tablename, accessright from dbc.allrights
where databasename='systemfe' and username='dbc' and tablename='opt_ras_table';
上述语句的执行结果为:
[plain]
*** Query completed. 12 rows found. 4 columns returned.
*** Total elapsed time was 1 second.
UserName DatabaseName TableName AccessRight
------------------------------ ------------------------------ ------------------------------ -----------
DBC SystemFe opt_ras_table DT
DBC SystemFe opt_ras_table U
DBC SystemFe opt_ras_table DG
DBC SystemFe opt_ras_table RF
DBC SystemFe opt_ras_table RS
DBC SystemFe opt_ras_table R
DBC SystemFe opt_ras_table I
DBC SystemFe opt_ras_table CG
DBC SystemFe opt_ras_table ST
DBC SystemFe opt_ras_table DP
DBC SystemFe opt_ras_table D
DBC SystemFe opt_ras_table IX
如下的SQL语句可以自动构建出授予权限的SQL语句(即GRANT语句): www.zzzyk.com
[sql]
SEL
TRIM(username)
,TRIM(databasename)
,TRIM(tablename)
,'GRANT '|| CASE
WHEN AccessRight = 'AF ' THEN 'ALTER FUNCTION'
WHEN AccessRight = 'AP ' THEN 'ALTER PROCEDURE'
WHEN AccessRight = 'AS ' THEN 'ABORT SESSION'
WHEN AccessRight = 'CD ' THEN 'CREATE DATABASE'
WHEN AccessRight = 'CF ' THEN 'CREATE FUNCTION'
WHEN AccessRight = 'CG ' THEN 'CREATE TRIGGER'
WHEN AccessRight = 'CM ' THEN 'CREATE MACRO'
WHEN AccessRight = 'CO ' THEN 'CREATE PROFILE'
WHEN AccessRight = 'CP ' THEN 'CHECKPOINT'
WHEN AccessRight = 'CR ' THEN 'CREATE ROLE'
WHEN AccessRight = '