哦上面写错了,应该是
CREATE TRIGGER [tri_cpxmdel] ON dbo.t_cpxm 
FOR DELETE
AS
  declare @cpid char    
  select @cpid=cpid from inserted
  delete from t_jinhuo where cpid=@cpid 如何改啊?

解决方案 »

  1.   

    FK_t_jinhuo_t_cpxm有外键关系
      

  2.   

    两个表t_cpxm和t_jinhuo(进货表)有主外键关系,删除主外键
      

  3.   

    agree:
    在关系图设置了关系,除非把关系删掉,否则无法删除!要么要先删有此表相关的数据行然而删除此表
      

  4.   

    我吧两者之间的外键关系删除了,执行delete from t_cpxm where cpid='01'可以删除了,但受影响的只有t_cpxm表中的记录,t_jinhuo 表中的记录不受影响怎么办啊~~
      

  5.   

    可以用foreign key
    create table t_cpxm (cpid varchar(100) not null primary key )
    create table t_jinhuo 
    (cpid varchar(100) EFERENCES _cpxm  (cpid )  ON DELETE  CASCADE  ON UPDATE CASCADE )
      

  6.   

    如果你要做到更新t_cpxm的内容 t_jinhuo 的也更新可以这样
    CREATE TRIGGER 名2 ON dbo.t_cpxm
    FOR update
    AS
    update t_jinhuo 
    set 列=aa.列 
    from inserted aa where aa.编号=t_jinhuo .编号
      

  7.   

    CREATE TRIGGER [tri_cpxmdel] ON dbo.t_cpxm 
    FOR DELETE
    AS
      delete t_jinhuo from inserted where t_jinhuo.cpid=inserted.cpid 
      

  8.   

    select @cpid=cpid from inserted
    这句,当删除不是一条记录时,出错!