Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server 2000 - on delete cascade problem

Status
Not open for further replies.

actionbasti

Programmer
Aug 10, 2005
8
US
Hello SQLers!

Working Code:

Code:
create table Rules(
    RuleID int identity(1,1) not null,
    UserID int not null,
    AccountIDSource int,
    AccountIDTarget int,
    ActionID int, 
    ActionValue money,
    NextActionDate datetime, 
    Foreign Key(UserID) References Users(UserID) on delete cascade,
    Foreign Key(AccountIDSource) References Accounts(AccountID),
    Foreign Key(AccountIDTarget) References Accounts(AccountID),
    Primary Key(RuleID)
);

NOT WORKING CODE:

Code:
create table Rules(
    RuleID int identity(1,1) not null,
    UserID int not null,
    AccountIDSource int,
    AccountIDTarget int,
    ActionID int, 
    ActionValue money,
    NextActionDate datetime, 
    Foreign Key(UserID) References Users(UserID) on delete cascade,
    Foreign Key(AccountIDSource) References Accounts(AccountID) [b][u]on delete cascade[/u][/b],
    Foreign Key(AccountIDTarget) References Accounts(AccountID) [b][u]on delete cascade[/u][/b],
    Primary Key(RuleID)
);
I get the follwoing error:


Introducing FOREIGN KEY constraint 'FK__Rules__AccountID__4262CC11' on table 'Rules' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

How can I accomplish what Im trying to show above:
There is an accounts table with unique account ids that are referenced twice in the rules table. so if i delete an account, i want the each rule's row to be deleted as well whether the reference is in the source, the target, OR BOTH.


Thanks

Seb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top