Foxtable(狐表)用户栏目专家坐堂 → 欢迎高手来PK


  共有3706人关注过本帖树形打印复制链接

主题:欢迎高手来PK

帅哥哟,离线,有人找我吗?
jspta
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1731 积分:11255 威望:0 精华:0 注册:2011/12/15 22:06:00
  发帖心情 Post By:2015/8/20 9:24:00 [显示全部帖子]

 1,删除掉关联字段无值的所有主表明细表记录. 2,删除掉主表有值,明细表无值的数据,3,删除掉明细表有数据,主表无对应数据的所有记录.

针对第一条,设置关联字段not null,避免第一问题产生
针对第二条,理论上不需要删除,只需要展示的时候,使用INNER JOIN就不会有。
针对第三条,程序设置最初就应当减少对删除的使用,可以对子表使用外键,避免误删除。当一个主表关联更多的子表的时候,这个问题会比较突出。

代码就不优化了,

Dim cmda As New SQLCommand
cmda.ConnectionName= gs_strActiveConn
cmda.CommandText = "delete A fr om " & args(0) & " A LEFT OUTER JOIN "& args(1) & " B on A."& args(2) &" = B."& args(2) &" where B."& args(2) &" Is null"
cmda.ExecuteNonQuery
cmda.CommandText = "delete A fr om " & args(1) & " A LEFT OUTER JOIN " & args(0) & " B on A." & args(2) & " = B." & args(2) &" where B." & args(2) &"  Is null"
cmda.ExecuteNonQuery

cmda.CommandText = "delete fr om "& args(0) & " where " & args(2) & " Is null"
cmda.ExecuteNonQuery
cmda.CommandText = "delete fr om "& args(1) &" where "& args(2) &" Is null"
cmda.ExecuteNonQuery



 回到顶部