Sql Compact create table error: The constraint specified is not valid

Hi all,

I am using SQL compact 3,.5 SP2 on my windows ce 6.0 device.

I need to dynamically create database and a table.

I have no problem creating database, but when I try to create table an error occurs. Can someone please help me out.

CREATE TABLE MYDATA(
    [SerialNumber] [nchar](13) NOT NULL,
    [Data_ID] [bigint] IDENTITY(1,1) NOT NULL,
    [DateTimeEnd] [datetime] NOT NULL,
    [Data1] [nvarchar](250) NULL,
    [Data2] [nvarchar](250) NULL,
    [Data3] [nvarchar](250) NULL,
    [CreationDate] [datetime] NULL CONSTRAINT [DF_MYDATA_CreationDate]  DEFAULT (getdate()),
    CONSTRAINT [PK_MYDATA] PRIMARY KEY CLUSTERED
    (
    [SerialNumber] ASC,
    [Data_ID] ASC,
    [DateTimeEnd] ASC
    ))

If I don't execute the last constraint table is created but when I run it with bolded part SqlCeException with "The constraint specified is not valid" error is thrown.

Best regards,

Grega

August 12th, 2013 5:40am

Hi  Gregec,

SQL Server Compact Edition does not support clustered indexes.
Please refer below articles.

Link showing that it does not support clustered indexes:
http://technet.microsoft.com/en-us/library/ms345331(v=sql.105).aspx

Link showing that PRIMARY KEYs are maintained by unique indexes:
http://technet.microsoft.com/en-us/library/ms173393.aspx

Thanks,
Candy Zhou

Free Windows Admin Tool Kit Click here and download it now
August 13th, 2013 7:40am

Thank you,

I totally missed that. I used script table in sql server management studio, and it created script with "clustered".

Best regards,

grega

August 19th, 2013 3:19am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics