Subject Re: [firebird-support] Re: could not find UNIQUE INDEX with specified columns
Author Helen Borrie
At 20:30 16/10/2008, you wrote:

> FbConnection c = new
>FbConnection("ServerType=1;User=SYSDBA;Password=masterkey;Dialect=3;Database=mydb.fdb");
>
> c.Open();
> FbTransaction t = c.BeginTransaction();
> FbCommand cmd = new FbCommand("CREATE TABLE \"test\"
>(field1 integer, field2 char(1024), field3 integer, PRIMARY KEY
>(field1))", c, t);
> cmd.ExecuteNonQuery();
> t.Commit();
> t.Dispose();
> t = c.BeginTransaction();
> FbCommand cmd1 = new FbCommand("ALTER TABLE \"test\" ADD
>FOREIGN KEY (field3) REFERENCES test(field1)", c, t);
> cmd1.ExecuteNonQuery();
> t.Commit();
> t.Dispose();
> c.Close();
>
>Throws Unhandled Exception: FirebirdSql.Data.Firebird.FbException:
>unsuccessful metadat a update could not find UNIQUE INDEX with
>specified columns

Well, the problem there is that your CREATE TABLE statement has failed because you can't apply a PK to a nullable column. You need to make that column NOT NULL.

./helen