❶ sql同時刪除多表記錄
你的問題說地不清楚。
首先,刪除操作只對單獨一張表有效的,除非用觸發器,存儲過程等程序控制。
如果是要兩條語句一起執行,出錯情況下回滾,可使用事務。
如果要在兩個表都有同一個ID情況下才刪除,可以使用存儲過程,在刪除前做下判斷。
❷ sql多表刪除
下面是復制來的,手上沒有oracle
總的思路是使用user_constraints這張數據字典表查關聯關系,constraint_type=「R」表示外鍵約束
1、查找表的所有索引(包括索引名,類型,構成列):
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name = i.table_name and t.table_name = 要查詢的表
2、查找表的主鍵(包括名稱,構成列):
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name = 要查詢的表
3、查找表的唯一性約束(包括名稱,構成列):
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'U' and au.table_name = 要查詢的表
4、查找表的外鍵(包括名稱,引用表的表名和對應的鍵名,下面是分成多步查詢):
select * from user_constraints c where c.constraint_type = 'R' and c.table_name = 要查詢的表
查詢外鍵約束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱
查詢引用表的鍵的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵引用表的鍵名
5、查詢表的所有列及其屬性
select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = 要查詢的表 ......
❸ SQL 如何多表刪除
不用同時去刪它,在A表(ID為主鍵的表)設置ID為"主鍵",B表ID為A表的"外鍵約束",並設置約束特性為"級聯",設置完成後,只要在A表刪除一行,B表的相關行會被自動刪除.
❹ sql語句多表刪除問題
原則上,同意youyuan1688和ytbelwxg的方法. 5個表,如果每個表都和lm_company表的comid欄位有直接主外鍵關系.那麼ytbelwxg的方法是最佳方案; 仔細看了你的連接條件,猜想,並不是每個表都和lm_company表的comid欄位有直接主外鍵關系.所以通過主外鍵級聯刪除的方案就不可行,那麼就必須逐個表來刪除,而且刪除的順序也有講究,先刪子表,再刪主表. 本例中,刪除的順序應該是e,d,c,b,a; --1.刪除e; sql1="delete from lm_newsinfo from lm_newsinfo as e, lm_company as a where a.comid=e.news_comid and a.comid=" + lblid.Text +";" --2.刪除d; sql2="delete from lm_message from lm_company as a ,lm_Yuzhan as b ,lm_Bookinfo as c ,lm_message as d where a.comid=b.yuzhan_comid and b.yuzhan_id=c.Bkinfo_yuzhanid and c.Bkinfo_id=d.message_bookid and a.comid=" + lblid.Text +";" --刪除c; sql3="delete from lm_Bookinfo from lm_company as a ,lm_Yuzhan as b ,lm_Bookinfo as c where a.comid=b.yuzhan_comid and b.yuzhan_id=c.Bkinfo_yuzhanid and a.comid=" + lblid.Text + ";" --刪除b; sql4="delete from lm_Yuzhan where yuzhan_comid=" + lblid.Text + ";" --刪除a; sql5="delete from lm_company where comid=" + lblid.Text + ";" --合並sql1,sql2,sql3,sql4,sql5 sql=sql1+sql2+sql3+sql4+sql5 --在你的客戶端執行sql命令串即可
❺ sql server資料庫怎樣同時刪除兩張表的數據
1、打開SQL Server 2008 並連接一個資料庫。
❻ 如何用SQL語句刪除一個表空間里的所有表
SELECT 'DROP TABLE ' || TABLE_NAME || ' CASCADE CONSTRAINTS' V_NAME
FROM DBA_TABLES
WHERE TABLESPACE_NAME = 'USERS';
按照表空間名查詢所有包含的表,並根據表名拼接刪除語句。
執行上面查詢語句生成的語句,即可刪除所有表。
❼ SQL如何直接批量刪除表
SQL直接批量刪除表的方法步驟:
所需工具原料:phpmyadmin。
1.數據操作前進行數據備份。
2.看需要刪除表的時間段,即什麼時間開始到什麼時間截至。記錄下數據表名稱和時間欄位名稱。
3.點擊上部"SQL"按鈕,進行sql語句執行。
4.打開文本框中輸入命定執行:
delete from wp_posts where `post_date` >='2010-01-01 00:00:00' and `post_date` < '2014-12-14 22:00:00:00'。
【命令語句意思】:從wp_posts數據表的post_date欄位中檢索文章創建日期在2010年1月1日0時和2014年12月14日22時之間的數據進行刪除操作。
5.成功後點擊上部「瀏覽」按鈕查看,表被刪除,sql執行語句成功。
刪除指令解析:
1.全部刪除:delete from table 。
2.部分刪除:delete from table a where nuid in(select nuid from table B)。
注意事項:
1.進行資料庫操作前須要進行資料庫備份。
2.資料庫操作是刪除數據文本,圖片等上傳文件不會受到影響。
❽ SQL批量刪除表的命令是
這個是別人提供的一個代碼,是刪除以test開頭的表,自己更改下條件就可以了可以試試看x0dx0adeclare@namevarchar(20)x0dx0awhile(exists(select*fromsysobjectswherenamelike'test%'))x0dx0abeginx0dx0aselect@name='test%'x0dx0aexec('droptable'+@name)x0dx0aend