简介
对接达梦数据库,程序需要根据日期自动创建数据库表,本篇记录自动创建表需要用到的相关SQL
SQL
取建表SQL
SELECT DBMS_METADATA.GET_DDL('Table', '表名',SYS_CONTEXT('userenv', 'current_schema')) FROM DUAL;
取表索引列表
select INDEX_NAME, INDEX_TYPE, TABLE_NAME from all_indexes WHERE table_name='表名' and TABLE_OWNER = SYS_CONTEXT('userenv', 'current_schema') AND index_type='NORMAL' AND uniqueness='NONUNIQUE';
取索引SQL
select dbms_metadata.get_ddl('INDEX','索引名',SYS_CONTEXT('userenv', 'current_schema')) from dual;
取表注释
SELECT COMMENTS FROM ALL_TAB_COMMENTS WHERE OWNER = SYS_CONTEXT('userenv', 'current_schema') AND TABLE_NAME = '表名';
取表字段注释
SELECT COLUMN_NAME, COMMENTS FROM USER_COL_COMMENTS WHERE OWNER = SYS_CONTEXT('userenv', 'current_schema') AND TABLE_NAME = '表名';