您现在的位置是:首页 >技术交流 >数据库查询所有表及实现拼接清表sql网站首页技术交流
数据库查询所有表及实现拼接清表sql
场景:
实施想让我提供一下清除库中所有表的数据脚本,我只知道一个show tables查询所有表
本想着select concat('delete from ',show tables)发现执行不了,总结不同数据库清表拼接语句。
mysql
查询所有表sql
show tables
拼接成清空库中所有表sql
select GROUP_CONCAT(concat('delete from ',table_name) SEPARATOR ";") delsql from information_schema.`TABLES` where table_schema='表约束名称';
PostgreSQL
查询所有表
方式一:通过pg_tables系统目录表查询
select tablename from pg_tables where schemaname='表约束名称';
方式二:通过information_schema.tables视图查询
select table_name FROM information_schema.tables where table_schema='表约束名称' ;
拼接成清空库中所有表sql
SELECT 'TRUNCATE ' || string_agg(format('%I.%I', table_schema, table_name), ', ') || ' CASCADE;'
FROM information_schema.tables
WHERE table_schema = '表约束名' and table_catalog='系统类目名';
ORACLE
查询所有表
方式一:查询当前用户中的表名
select t.table_name from user_tables t where t.TABLESPACE_NAME='表创建用户名';
方式二:查询所有用户中的表名
select t.table_name from all_tables t where t.TABLESPACE_NAME='表创建用户名';
拼接成清空库中所有表sql
SELECT 'DELETE FROM ' || table_name || ';' FROM user_tables ;





U8W/U8W-Mini使用与常见问题解决
QT多线程的5种用法,通过使用线程解决UI主界面的耗时操作代码,防止界面卡死。...
stm32使用HAL库配置串口中断收发数据(保姆级教程)
分享几个国内免费的ChatGPT镜像网址(亲测有效)
Allegro16.6差分等长设置及走线总结