我不是高手,参与参与应该是现删除从表记录,再删除主表记录,至少SQL Server 是这么实现的

解决方案 »

  1.   

    ORACLE中有语法实现。
    on delete cascade就表示当你删除父表数据时,同时删除有外键指向子表相关项。
      

  2.   

    SQL Server 可以做到我刚才试验过!!!!
    建立外键关系的时候,选择
    [对 INSERT 和 UPDATE 强制关系]
    [级联更新相关的字段]
    无论何时更新主键值,都指示 DBMS 自动更新该关系的外键值。
    [级联删除相关的字段]
    无论何时删除主表的被引用行,都指示 DBMS 自动删除外键表的行
      

  3.   

    每种sql server或许不同.这是interbase下的 sql格式:ALTER TABLE <table_name> ADD CONSTRAINT <constraint_name>REFERENCES other_table [(other_col [, other_col …])][ON DELETE {NO ACTION|CASCADE|SET DEFAULT|SET NULL}][ON UPDATE {NO ACTION|CASCADE|SET DEFAULT|SET NULL}]其中:
    Used with REFERENCES: Changes a foreign key whenever the referenced primary key changes; valid options are:&#8226; [Default] NO ACTION: Does not change the foreign key; may cause the primary key update to fail due to referential integrity checks &#8226; CASCADE: For ON DELETE, deletes the corresponding foreign key; for ON UPDATE, updates the corresponding foreign key to the new value of the primary key&#8226; SET NULL: Sets all the columns of the corresponding foreign key to NULL&#8226; SET DEFAULT: Sets every column of the corresponding foreign key is set to its default value in effect when the referential integrity constraint is defined; when the default for a foreign column changes after the referential integrity constraint is defined, the change does not have an effect on the default value used in the referential integrity constraint