❶ 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