[RESOLVED] Sql Compact: The constraint specified is not valid.
Hello.
I'm trying to create a couple of tables in my SqlServerCE database (sdf).
I'm using the following commands:
Code:
CREATE TABLE SUBJECTS(
CODE bigint NOT NULL CONSTRAINT SUBJECTS_PK PRIMARY KEY,
NAME nVarChar(40) NOT NULL,
SOKR nVarChar(10) NULL
)
CREATE TABLE REGIONS(
CODE bigint NOT NULL CONSTRAINT REGIONS_PK PRIMARY KEY,
SUBJ_CODE bigint NULL CONSTRAINT SUBJECTS_CODE FOREIGN KEY REFERENCES SUBJECTS(CODE),
NAME nVarChar(40) NOT NULL,
SOKR nVarChar(10) NULL
)
The first one goes OK, but the second one throws an exception saying:
The constraint specified is not valid.
The question is, how should I add a foreign key to a table?
Re: Sql Compact: The constraint specified is not valid.
Never mind. Figured out.
The correct syntax is here:
Code:
CREATE TABLE REGIONS(
CODE bigint NOT NULL CONSTRAINT [PK_REGIONS] PRIMARY KEY,
SUBJ_CODE bigint NULL,
NAME nVarChar(40) NOT NULL,
SOKR nVarChar(10) NULL,
FOREIGN KEY (SUBJ_CODE) REFERENCES SUBJECTS(CODE)
)