Skip to content

Commit

Permalink
Test to show a nasty little bug with foreign keys with same name wher…
Browse files Browse the repository at this point in the history
…e CASCADE is picked up by non-cascading FKs if another FK with same name in different schema is CASCADE
  • Loading branch information
danbrad committed Apr 21, 2016
1 parent 8dc3b7f commit 8655661
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/DatabaseTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ CONSTRAINT [PK_1a] PRIMARY KEY (a)
CREATE TABLE [dbo].[t1b]
(
a INT NOT NULL,
CONSTRAINT [FKName] FOREIGN KEY ([a]) REFERENCES [dbo].[t1a] ([a])
CONSTRAINT [FKName] FOREIGN KEY ([a]) REFERENCES [dbo].[t1a] ([a]) ON UPDATE CASCADE
)
CREATE TABLE [s2].[t2a]
Expand All @@ -298,7 +298,7 @@ CONSTRAINT [PK_2a] PRIMARY KEY (a)
CREATE TABLE [s2].[t2b]
(
a INT NOT NULL,
CONSTRAINT [FKName] FOREIGN KEY ([a]) REFERENCES [s2].[t2a] ([a])
CONSTRAINT [FKName] FOREIGN KEY ([a]) REFERENCES [s2].[t2a] ([a]) ON DELETE CASCADE
)
";
Expand All @@ -321,6 +321,11 @@ CONSTRAINT [FKName] FOREIGN KEY ([a]) REFERENCES [s2].[t2a] ([a])
Assert.AreEqual(db.ForeignKeys[0].Name, db.ForeignKeys[1].Name);
Assert.AreNotEqual(db.ForeignKeys[0].Table.Owner, db.ForeignKeys[1].Table.Owner);

Assert.AreEqual("CASCADE", db.FindForeignKey("FKName", "dbo").OnUpdate);
Assert.AreEqual("NO ACTION", db.FindForeignKey("FKName", "s2").OnUpdate);

Assert.AreEqual("NO ACTION", db.FindForeignKey("FKName", "dbo").OnDelete);
Assert.AreEqual("CASCADE", db.FindForeignKey("FKName", "s2").OnDelete);
}

public void TestScriptViewInsteadOfTrigger() {
Expand Down

0 comments on commit 8655661

Please sign in to comment.