“清空临时表数据”的方法,取决于你用的数据库类型以及临时表的作用范围。下面按常见数据库分别说明:
TRUNCATE TABLE #temp_table;
-- 或
DELETE FROM #temp_table;
TRUNCATE TABLE temp_table;
-- 或
DELETE FROM temp_table;
注意:
- 临时表只在当前会话可见
- 断开连接会自动清空
TRUNCATE TABLE #temp_table;
-- 或
DELETE FROM #temp_table;
TRUNCATE TABLE ##temp_table;
TRUNCATE TABLE temp_table;
-- 或
DELETE FROM temp_table;
COMMIT 后数据会自动清空(如果是 ON COMMIT DELETE ROWS)
TRUNCATE TABLE temp_table;
TRUNCATE TABLE temp_table;
-- 或
DELETE FROM temp_table;
会话结束临时表自动删除
| 对比项 | TRUNCATE | DELETE |
|---|---|---|
| 速度 | 快 | 慢 |
| 可回滚 | 多数库不支持 | 支持 |
| 触发触发器 | 不触发 | 触发 |
| 自增列重置 | 会重置 | 不会 |
# 或前缀如果你能告诉我:
我可以给你最准确的一条 SQL。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。