1
Vote

Create table with composite Pirmary Key fail

description

The code:
DBCreateTableQuery createTable = DBCreateTableQuery.Create.Table("Test");
createTable.Add("c1", DbType.String, 100, DBColumnFlags.PrimaryKey);
createTable.Add("c2", DbType.String, 100, DBColumnFlags.PrimaryKey);
will produce the SQL statement:
CREATE TABLE [Test] (
        [c1] NVARCHAR(100) PRIMARY KEY NOT NULL, 
        [c2] NVARCHAR(100) PRIMARY KEY NOT NULL)
This code isn't valid. Primary Key has to be expressed as a constraint:
CREATE TABLE [Test] (
        [c1] NVARCHAR(100) NOT NULL, 
        [c2] NVARCHAR(100) NOT NULL, 
        PRIMARY KEY  ([c1], [c2]) )

comments

perceiveit wrote Sep 23, 2014 at 12:42 PM

Nilps - what database engine are you using. Looks like MS SQL Server, but cannot be 10% sure.

Then we can look at this and see if there is a workaround.

nlips wrote Sep 23, 2014 at 6:21 PM

Yes I'm using SQLServer but I think that for all systems, if the Primary Key contains multiple columns ,it has to be expressed as a constraint.
I suggest the patch #16834