create trigger tr_delete_a
on a
for delete
as
delete b where aid in (select id from deleted)
goB表(从表)的字段AID对应A表(主表)主健字段ID
on a
for delete
as
delete b where aid in (select id from deleted)
goB表(从表)的字段AID对应A表(主表)主健字段ID
还是无法删除。我执行删除时有以下错误:
DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_JOB_SIGHT'. The conflict occurred in database 'TourData', table 'JOB', column 'SIGHT'.
The statement has been terminated.帮帮忙。这事很急呀。
create trigger tr_delete_a
on a
instead of delete
as
delete b where aid in (select id from deleted)
go
instead of delete
这句话无法编译。我在SQL SERVER7.0中没有找到级联删除的选项,好象只有级联更新。
ALTER TABLE [dbo].[UserFriend] ADD
CONSTRAINT [FK_UserFriend_UserID2UserInfo_UserID] FOREIGN KEY
(
[UserID]
) REFERENCES [dbo].[UserInfo] (
[UserID]
) ON DELETE CASCADE 主要就是on delete cacade这一句了
alter table tablename
drop constraint fk_..
alter table tablename
nocheck
constraint fk_....2.create trigger for delete
create trigger triggername
on tablename(PK)
for delete
as
delete tablename(contain FK) where tablename.id=deleted.id
go
3.The best way using delete cascade.
alter table tablename
add constraint fk_....
foregin key(column)
references tablename(PK)(column)
on delete cascade