从同一个sql中的两个表中删除数据的问题 [英] problem to delete data from two table in the same sql

查看:87
本文介绍了从同一个sql中的两个表中删除数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题是从同一个sql中的两个表中删除数据,并且我已经连接到表之间。如何删除



例如



 CommandText =  从sub_main.action = is_main.action上的sub_main内连接is_main删除sub_main,其中row.sub_main =' + dataGridView1 .CurrentRow.Cells [ 1 ]。值+  '和action.sub_main =' + dataGridView1.CurrentRow.Cells [ 0 ]。值+  '和action.is_main =' + dataGridView1.CurrentRow.Cells [ 2 ]。值+  '; 

解决方案

使用SQL SERVER中的单个DELETE语句无法从多个表中删除行。



在这两个表之间创建一个外键并使用在DELET E CASCADE。



看看这个



单个SQL查询删除两个表中的记录 [ ^ ]

I have a problem to delete data from two table in the same sql and i have join between to table . how can delete

for example

CommandText = "delete sub_main from sub_main inner join is_main on sub_main.action=is_main.action where row.sub_main='" + dataGridView1.CurrentRow.Cells[1].Value + "' and action.sub_main='" + dataGridView1.CurrentRow.Cells[0].Value + "' and action.is_main='" + dataGridView1.CurrentRow.Cells[2].Value + "'";

解决方案

It is not possible to delete rows from multiple tables using single DELETE statement in SQL SERVER.

Create a foreign key between these two tables and use ON DELETE CASCADE.

Have a look at this one

Single SQL Query to delete records in two tables[^]


这篇关于从同一个sql中的两个表中删除数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆