2017-02-03 44 views
0

我想要一些FK關係如下面的代碼,讓我有一個表員工& EmpMetadata是否可以在Sqite中創建與文本列的外鍵關係?

CREATE TABLE [Employee] (
    [Empid] integer PRIMARY KEY NOT NULL, 
    [FName] text NOT NULL, 
    [lname] text NOT NULL 
) 

CREATE TABLE [EmpMetadata] (
    [Name] text NOT NULL, 
    [Value] text NOT NULL, 
    [lname] text, 
    PRIMARY KEY (Name, Value, lname), 
    CONSTRAINT [FK_Emp] FOREIGN KEY ([lname]) REFERENCES [Employee] 
    ([lname]) ON UPDATE CASCADE ON DELETE CASCADE 
); 

當我excecuting它,它成功地excecuted,但是當m產生EDMX這種情況的關係沒有顯示。這兩個表格顯示爲單獨的實體。

我在Employee表中使用了Constraint lname_unique UNIQUE(lname),雖然它正確地執行了,但在edmx文件中它沒有顯示關係。

但是,如果我在EDMX文件中使用

CREATE TABLE [EmpMetadata] (
     [Id] integer NOT NULL, 
     [Value] text NOT NULL, 
     [lname] text, 
     PRIMARY KEY (Id, Value, lname), 
     CONSTRAINT [FK_Emp] FOREIGN KEY ([Id]) REFERENCES [Employee] 
     ([Empid]) ON UPDATE CASCADE ON DELETE CASCADE 
    ); 

然後,FK關係是否正確顯示。

誰能告訴我爲什麼它不生成FK關係,如果我使用文本列作爲外鍵來關聯這些表?

回答

0

所以我就soultion表結構應該是這樣的:

CREATE TABLE [Employee] (
    [Empid] integer NOT NULL, 
    [FName] text NOT NULL, 
    [lname] text NOT NULL, 
    Primary Key (Empid, lname) 
) 

CREATE TABLE [EmpMetadata] (
    [Name] text NOT NULL, 
    [Value] text NOT NULL, 
    [lname] text, 
    PRIMARY KEY (Name, Value, lname), 
    CONSTRAINT [FK_Emp] FOREIGN KEY ([lname]) REFERENCES [Employee] 
    ([lname]) ON UPDATE CASCADE ON DELETE CASCADE 
); 
相關問題