首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

==============删除关系表的有关问题===========

2012-05-04 
求一个删除关系表的问题SQL code相册表h_albuma_id inta_name varchar(50)照片

==============求一个删除关系表的问题===========

SQL code
相册表h_albuma_id inta_name varchar(50)照片表h_photo p_id inta_id int 和h_album的外键p_name varhcar(50)评论表h_commentc_id intc_relatedid int 关联的ID,此处关联h_photo的p_id,但不是外键c_content==================问题=====================现在要删除h_album:delete from h_album where a_id=1----此处假设要删除的相册id为1并删除a_id为1的照片表h_photo:delete from h_photo where a_id=1删除照片表之前要先删除该相册a_id为1的所有照片的所有评论.该怎么写呢?


[解决办法]
探讨

自己写出来了
SQL code

delete c from h_comment c inner join h_photo p on p.p_id=c.c_relatedid where c.type=3 and p.a_id=1



想问下.为什么这里删除的是h_comment以及关联h_photo
为什么删除掉的数据只有h_comment的,而不会影响h_photo呢?

热点排行