kingbase导出所有表的建表语句
时间: 2023-08-02 18:11:45 浏览: 226
基本元素-《信息安全技术 物联网安全参考模型及通用要求》gb_t 37044-2018
可以使用以下SQL语句导出Kingbase所有表的建表语句:
```
SELECT 'CREATE TABLE ' || relname || E'(\n' || column_definition || E'\n);' AS create_table_sql
FROM pg_class
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
JOIN (
SELECT attrelid, string_agg(column_definition, E',\n') AS column_definition
FROM (
SELECT attrelid, attname || ' ' || format_type(atttypid, atttypmod) AS column_definition
FROM pg_attribute
WHERE NOT attisdropped AND attnum > 0
ORDER BY attnum
) sub
GROUP BY attrelid
) cols ON cols.attrelid = pg_class.oid
WHERE relkind = 'r' AND nspname = 'public'
ORDER BY relname;
```
执行该SQL语句后,会输出所有表的建表语句,可以将结果保存到文件中。注意,该语句只能导出public模式下的表,如果需要导出其他模式下的表,需要修改`nspname`的值。
阅读全文