从2表中删除,同时? [英] Deleting from 2 tables at the same time?

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

问题描述

我使用asp.net和SQL Server。我有2表:类别和产品。在产品表,我有作为的categoryId FK。我想要做的是:当我从类别表中删除类,我想,所有从该类别中的产品将在产品表中删除。如何才能做到这一点(我preFER与存储过程,但它不是mandetory)?

I'm using asp.net and sql server. i have 2 tables: Categories and Products. in the products table i have categoryId as FK. what i want to do is: when i delete category from the category table, i want that all the products from that category will be deleted in the products table. how can this be done ( i prefer with store procedure but its not mandetory)?

推荐答案

您可以定义FK使用DELETES CASCADE。否则,你将需要删除首先是产品的类别,然后删除该类别。

You could define that FK to use DELETES CASCADE. Otherwise, you will need to delete first all the products in the category and then delete the category.

这篇关于从2表中删除,同时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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