diff --git a/model/Database.cs b/model/Database.cs index 097000d8..24485263 100644 --- a/model/Database.cs +++ b/model/Database.cs @@ -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"]); diff --git a/test/DatabaseTester.cs b/test/DatabaseTester.cs index b5951b2c..58f9b6e4 100644 --- a/test/DatabaseTester.cs +++ b/test/DatabaseTester.cs @@ -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] @@ -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 ) "; @@ -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() {