當前位置:首頁 » 編程語言 » sql多表刪除

sql多表刪除

發布時間: 2024-12-22 07:21:23

sql資料庫怎麼刪除多張表中的全部數據

delete from 表--刪除數據,記錄日誌,耗時較長
truncate table 表--刪除數據,不記錄日誌,刪除較快
drop table 表--刪除數據,刪除表

Ⅱ 資料庫,資料庫sql命令,刪除多表關聯索引數據

這么個問題,要寫好多語句的,都沒有分的。

首先,你的表肯定是做了外鍵等約束的,所以刪除,要從最外層刪除。假設你的資料庫是Sql Server的。

1、技能表
delete from 技能表 where 人物id in (select 人物id from 人物表 where 賬號id in (select 賬號id from 賬號表 where datediff(day,上次登錄時間lasttime,getdate())>=3))

2、裝備屬性表
delete from 裝備屬性表 where 裝備id in (select 裝備id from 裝備表 where 人物id in (select 人物id from 人物表 where 賬號id in (select 賬號id from 賬號表 where datediff(day,上次登錄時間lasttime,getdate())>=3)))

3、裝備表
delete from 裝備表 where 人物id in (select 人物id from 人物表 where 賬號id in (select 賬號id from 賬號表 where datediff(day,上次登錄時間lasttime,getdate())>=3))

4、人物表
delete from 人物表 where 賬號id in (select 賬號id from 賬號表 where datediff(day,上次登錄時間lasttime,getdate())>=3)

5、賬號表
delete from 賬號表 where datediff(day,上次登錄時間lasttime,getdate())>=3

Ⅲ 如何用一條sql語句清空多張表中的記錄請各位大神幫忙

不支持同時update、delete、truncate多張表,只能一個一個的操作
可以寫一個游標,逐步執行delete操作

Ⅳ sql刪除多表多條件

delete from c where 收款單編號 in
(select 收款單編號 from b where id in
(select 計費id from a where 計費日期>='2012-07-01' and 計費日期<'2012-08-01'));

delete from b where id in
(select 計費id from a where 計費日期>='2012-07-01' and 計費日期<'2012-08-01') ;

delete from a where 計費日期>='2012-07-01' and 計費日期<'2012-08-01' ;

commit;

熱點內容
雲伺服器2核4g3m什麼意思 發布:2025-07-04 10:23:34 瀏覽:239
蘋果手機如何往安卓手機導通訊錄 發布:2025-07-04 10:19:11 瀏覽:132
未來之役如何換伺服器 發布:2025-07-04 10:13:51 瀏覽:216
curlc上傳 發布:2025-07-04 09:59:35 瀏覽:881
沒有編譯器能運行c程序嗎 發布:2025-07-04 09:54:38 瀏覽:308
創建配置目錄錯誤是什麼意思 發布:2025-07-04 09:53:35 瀏覽:49
為什麼租憑伺服器不能玩了 發布:2025-07-04 09:03:01 瀏覽:984
安卓手機減肥軟體哪個好 發布:2025-07-04 08:51:17 瀏覽:997
Oracle查看資料庫歸檔 發布:2025-07-04 08:44:53 瀏覽:608
950買什麼配置好 發布:2025-07-04 08:39:39 瀏覽:611