Skip to content

Commit

Permalink
Merge pull request #91 from danbrad/FKSameNameOnUpOnDel
Browse files Browse the repository at this point in the history
Fk same name on up on del
  • Loading branch information
sethreno committed Apr 21, 2016
2 parents c41b81e + 5246901 commit 69d70e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion model/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
DELETE_RULE,
fk.is_disabled
from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
inner join sys.foreign_keys fk on rc.CONSTRAINT_NAME = fk.name";
inner join sys.foreign_keys fk on rc.CONSTRAINT_NAME = fk.name and rc.CONSTRAINT_SCHEMA = OBJECT_SCHEMA_NAME(fk.parent_object_id)";
using (var dr = cm.ExecuteReader()) {
while (dr.Read()) {
var fk = FindForeignKey((string) dr["CONSTRAINT_NAME"], (string)dr["TABLE_SCHEMA"]);
Expand Down
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 69d70e8

Please sign in to comment.