且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SQL Server CE(精简版)数据库中创建外键关系?

更新时间:2023-02-04 10:10:40

不幸的是,目前没有设计师支持(不像SQL Server 2005) CE。要建立关系,您需要使用SQL命令,例如:

  ALTER TABLE Orders 
ADD CONSTRAINT FK_Customer_Order
FOREIGN KEY(CustomerId)参考客户(CustomerId)

如果您正在做CE开发,常见问题:



编辑:在Visual Studio 2008中,现在可以通过右键单击您的表格在GUI中执行。 >

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 Edition DB using Management Studio as far as I know. Any ideas?

Unfortunately there is currently no designer support (unlike for SQL Server 2005) for building relationships between tables in SQL Server CE. To build relationships you need to use SQL commands such as:

ALTER TABLE Orders
ADD CONSTRAINT FK_Customer_Order
FOREIGN KEY (CustomerId) REFERENCES Customers(CustomerId)

If you are doing CE development, i would recomend this FAQ:

EDIT: In Visual Studio 2008 this is now possible to do in the GUI by right-clicking on your table.