从两个连接在一起的sql表中删除行 [英] Delete row from two sql tables that join together

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

问题描述

有两个表:



There are two tables:

Table1 : UserID Name Job
Table2 : BookID Book Car UserID





我在一个wpf数据网格中加载这两个表格:





I load these two tables in one wpf datagrid:

da.SelectCommand = new SqlCommand("select Table1.UserID, Table1.Name, Table1.Job, Table2.Book, Table2.Car from Table1 inner join Table2 on Table1.UserID = Table2.UserID");




如何根据BookID从Table2中删除一行?

谢谢



How can delete a row from Table2 based on BookID?
thanks

推荐答案





基本上你不能从包含外键的表中删除记录。如果你想删除记录,有两种方法可以做到这一点。



1.在sql表中创建级联删除属性。但这也会删除父表中的记录。建议不要这样做。



2.创建一个名为IsDeleted的列为布尔类型的列,并将值设置为1,要删除哪个记录。大多数行业都遵循这一点。



谢谢


Basically you can''t be able to delete the record from the table having a foreign key in it. If you want to delete the record there are 2 ways of doing that.

1. Make your "cascade delete property" on in sql tables. But this will delete the records from the parent table too. This is not atall recomended.

2. Make a column named as IsDeleted of boolean type and set the value to 1 which record you want to delete. This is followed in most of the industries.

Thanks


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

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