How do you create a foreign key relationship in a SQL Server CE (Compact Edition) Database?

前端 未结 7 811
闹比i
闹比i 2021-02-04 23:44

Visual Studio 2005 doesn\'t provide an interface for creating relationships between tables in a SQL Server CE database (I\'m using version 3.0) and you can\'t open a Compact Edi

7条回答
  •  轮回少年
    2021-02-05 00:16

    You need to create a query (in Visual Studio, right-click on the DB connection -> New Query) and execute the following SQL:

    ALTER TABLE tblAlpha
    ADD CONSTRAINT MyConstraint FOREIGN KEY (FK_id) REFERENCES
    tblGamma(GammaID)
    ON UPDATE CASCADE
    

    To verify that your foreign key was created, execute the following SQL:

    SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
    

    Credit to E Jensen (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=532377&SiteID=1)

提交回复
热议问题