切换到SYSDBA用户,才能查询到数据字典的信息。
而且由于存在多个数据库,不同数据库中查询的结果只是当前数据库中的信息,而不是总体信息,部分总的信息只保存在SYSTEM数据库中,比如LOGIN信息:
SQL>select name, defaultdb from syslogins;
select name, defaultdb from syslogins;
name defaultdb
1 SYSDBA 0
2 test 4
2 rows got
time used: 1.400(ms) clock tick:2322140.
select name, defaultdb from syslogins;
name defaultdb
1 SYSDBA 0
2 test 4
2 rows got
time used: 1.400(ms) clock tick:2322140.
难道只有SYSDBA用户才能获取对象的信息,而普通用户无法获得信息吗,其实也不是,在达梦数据库中,USER/ALL视图被合并在一起,且视图的前缀信息被去掉。比如TABLES中就是当前用户拥有或可以访问到的表。
只不过这些信息并不再当前用户中,而是存在于INFO_SCHEM或INFORMATION_SCHEMA模式中(其中INFO_SCHEM中仅包含最常用的几个视图):
SQL>login
server name:localhost
user name:test
password:
port:12345
dm_login time used:50.451(ms)
SQL>select table_schema, table_name, table_type
2 from test.information_schema.tables
3 where table_schema in ('test', 'INFORMATION_SCHEMA');
select table_schema, table_name, table_type
from test.information_schema.tables
where table_schema in ('test', 'INFORMATION_SCHEMA');
table_schema table_name table_type
1 INFORMATION_SCHEMA INFORMATION_SCHEMA_CATALOG_NAME BASE TABLE
2 test t BASE TABLE
3 test T1 BASE TABLE
4 test T_BAK BASE TABLE
5 test t_bool BASE TABLE
6 test t_char BASE TABLE
7 test t_date BASE TABLE
8 test T_INC BASE TABLE
9 test T_LOB BASE TABLE
10 test T_LOBDMBLOB BASE TABLE
11 test t_num BASE TABLE
12 test T_PART BASE TABLE
13 test T_TAB BASE TABLE
14 test t_test BASE TABLE
15 test t_test3 BASE TABLE
16 test t_text BASE TABLE
17 test t_textDMBLOB BASE TABLE
18 test t_type BASE TABLE
19 INFORMATION_SCHEMA CHECK_CONSTRAINTS VIEW
20 INFORMATION_SCHEMA COLUMN_EXPLICT_IN_PRIVILEGES VIEW
21 INFORMATION_SCHEMA COLUMN_EXPLICT_OUT_PRIVILEGES VIEW
22 INFORMATION_SCHEMA COLUMN_IMPLICT_IN_BYSELF VIEW
23 INFORMATION_SCHEMA COLUMN_IMPLICT_IN_PRIVILEGES VIEW
24 INFORMATION_SCHEMA COLUMN_IMPLICT_OUT_PRIVILEGES VIEW
25 INFORMATION_SCHEMA COLUMN_PRIVILEGES VIEW
26 INFORMATION_SCHEMA COLUMNS VIEW
27 INFORMATION_SCHEMA COLUMNS_TAB VIEW
28 INFORMATION_SCHEMA COLUMNS_VIEW VIEW
29 INFORMATION_SCHEMA KEY_COLUMN_USAGE VIEW
30 INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS VIEW
31 INFORMATION_SCHEMA SCHEMATA VIEW
32 INFORMATION_SCHEMA TABLE_CONSTRAINTS VIEW
33 INFORMATION_SCHEMA TABLE_PRIVILEGES VIEW
34 INFORMATION_SCHEMA TABLES VIEW
35 INFORMATION_SCHEMA TABLES_NET VIEW
36 INFORMATION_SCHEMA TABLES_WITH_ID VIEW
37 INFORMATION_SCHEMA USAGE_PRIVILEGES VIEW
38 INFORMATION_SCHEMA VIEW_TABLE_USAGE VIEW
39 INFORMATION_SCHEMA VIEW_TABLE_USAGE_NET VIEW
40 INFORMATION_SCHEMA VIEW_VIEW_USAGE_NET VIEW
41 INFORMATION_SCHEMA VIEWS VIEW
42 INFORMATION_SCHEMA VIEWS_NET VIEW
43 test V_TEST VIEW
43 rows got
time used: 51.986(ms) clock tick:86851070.
server name:localhost
user name:test
password:
port:12345
dm_login time used:50.451(ms)
SQL>select table_schema, table_name, table_type
2 from test.information_schema.tables
3 where table_schema in ('test', 'INFORMATION_SCHEMA');
select table_schema, table_name, table_type
from test.information_schema.tables
where table_schema in ('test', 'INFORMATION_SCHEMA');
table_schema table_name table_type
1 INFORMATION_SCHEMA INFORMATION_SCHEMA_CATALOG_NAME BASE TABLE
2 test t BASE TABLE
3 test T1 BASE TABLE
4 test T_BAK BASE TABLE
5 test t_bool BASE TABLE
6 test t_char BASE TABLE
7 test t_date BASE TABLE
8 test T_INC BASE TABLE
9 test T_LOB BASE TABLE
10 test T_LOBDMBLOB BASE TABLE
11 test t_num BASE TABLE
12 test T_PART BASE TABLE
13 test T_TAB BASE TABLE
14 test t_test BASE TABLE
15 test t_test3 BASE TABLE
16 test t_text BASE TABLE
17 test t_textDMBLOB BASE TABLE
18 test t_type BASE TABLE
19 INFORMATION_SCHEMA CHECK_CONSTRAINTS VIEW
20 INFORMATION_SCHEMA COLUMN_EXPLICT_IN_PRIVILEGES VIEW
21 INFORMATION_SCHEMA COLUMN_EXPLICT_OUT_PRIVILEGES VIEW
22 INFORMATION_SCHEMA COLUMN_IMPLICT_IN_BYSELF VIEW
23 INFORMATION_SCHEMA COLUMN_IMPLICT_IN_PRIVILEGES VIEW
24 INFORMATION_SCHEMA COLUMN_IMPLICT_OUT_PRIVILEGES VIEW
25 INFORMATION_SCHEMA COLUMN_PRIVILEGES VIEW
26 INFORMATION_SCHEMA COLUMNS VIEW
27 INFORMATION_SCHEMA COLUMNS_TAB VIEW
28 INFORMATION_SCHEMA COLUMNS_VIEW VIEW
29 INFORMATION_SCHEMA KEY_COLUMN_USAGE VIEW
30 INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS VIEW
31 INFORMATION_SCHEMA SCHEMATA VIEW
32 INFORMATION_SCHEMA TABLE_CONSTRAINTS VIEW
33 INFORMATION_SCHEMA TABLE_PRIVILEGES VIEW
34 INFORMATION_SCHEMA TABLES VIEW
35 INFORMATION_SCHEMA TABLES_NET VIEW
36 INFORMATION_SCHEMA TABLES_WITH_ID VIEW
37 INFORMATION_SCHEMA USAGE_PRIVILEGES VIEW
38 INFORMATION_SCHEMA VIEW_TABLE_USAGE VIEW
39 INFORMATION_SCHEMA VIEW_TABLE_USAGE_NET VIEW
40 INFORMATION_SCHEMA VIEW_VIEW_USAGE_NET VIEW
41 INFORMATION_SCHEMA VIEWS VIEW
42 INFORMATION_SCHEMA VIEWS_NET VIEW
43 test V_TEST VIEW
43 rows got
time used: 51.986(ms) clock tick:86851070.
其中test模式下的表就是当前用户的表,而INFORMATION_SCHEMA模式下的视图,就是普通用户可以获取系统信息的视图。 只不过在达梦数据库中,没有提供全局的同义词来进行访问,所以在查询数据字典信息的时候,一般用户必须要指定模式名称。