<p>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?</p>

[{'answer_id': 46832, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 7, 'selected': True, 'text': '<p>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:</p>\n\n<pre><code>ALTER TABLE Orders\nADD CONSTRAINT FK_Customer_Order\nFOREIGN KEY (CustomerId) REFERENCES Customers(CustomerId)\n</code></pre>\n\n<p>If you are doing CE development, i would recomend this FAQ:</p>\n\n<p><strong>EDIT</strong>: In Visual Studio 2008 this is now possible to do in the GUI by right-clicking on your table.</p>\n'}, {'answer_id': 46834, 'author': 'Ryan Shripat', 'author_id': 1943, 'author_profile': 'https://Stackoverflow.com/users/1943', 'pm_score': 3, 'selected': False, 'text': '<p>You need to create a query (in Visual Studio, right-click on the DB connection -> New Query) and execute the following SQL:</p>\n\n<pre><code>ALTER TABLE tblAlpha\nADD CONSTRAINT MyConstraint FOREIGN KEY (FK_id) REFERENCES\ntblGamma(GammaID)\nON UPDATE CASCADE\n</code></pre>\n\n<p>To verify that your foreign key was created, execute the following SQL:</p>\n\n<pre><code>SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS\n</code></pre>\n\n<p>Credit to E Jensen (<a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=532377&amp;SiteID=1" rel="noreferrer">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=532377&amp;SiteID=1</a>)</p>\n'}, {'answer_id': 650900, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': False, 'text': '<p>Visual Studio 2008 <em>does</em> have a designer that allows you to add FK\'s.  Just right-click the table... Table Properties, then go to the "Add Relations" section.</p>\n'}, {'answer_id': 1258873, 'author': 'Rob', 'author_id': 108141, 'author_profile': 'https://Stackoverflow.com/users/108141', 'pm_score': 2, 'selected': False, 'text': "<p>Alan is correct when he says there's designer support.  Rhywun is incorrect when he implies you cannot choose the foreign key table.  What he means is that in the UI the foreign key table drop down is greyed out - all that means is he has not right clicked on the correct table to add the foreign key to.</p>\n\n<p>In summary, right click on the foriegn key table and then via the 'Table Properties' > 'Add Relations' option you select the related primary key table.</p>\n\n<p>I've done it numerous times and it works.</p>\n"}, {'answer_id': 16894739, 'author': 'shahwazir haqmall', 'author_id': 2447464, 'author_profile': 'https://Stackoverflow.com/users/2447464', 'pm_score': 1, 'selected': False, 'text': '<pre><code>create table employee\n(\n   empid int,\n   empname varchar(40),\n   designation varchar(30),\n   hiredate datetime, \n   Bsalary int,\n   depno constraint emp_m foreign key references department(depno)\n)\n</code></pre>\n\n<p>We should have an primary key to create foreign key or relationship between two or more table . </p>\n'}, {'answer_id': 20942153, 'author': 'Tharaka', 'author_id': 2390020, 'author_profile': 'https://Stackoverflow.com/users/2390020', 'pm_score': 1, 'selected': False, 'text': '<p>I know it\'s a "very long time" since this question was first asked. Just in case, if it helps someone,</p>\n\n<p>Adding relationships is well supported by MS via SQL Server Compact Tool Box (<a href="https://sqlcetoolbox.codeplex.com/" rel="nofollow noreferrer">https://sqlcetoolbox.codeplex.com/</a>). Just install it, then you would get the option to connect to the Compact Database using the Server Explorer Window. Right click on the primary table , select "Table Properties". You should have the following window, which contains "Add Relations" tab allowing you to add relations.</p>\n\n<p><img src="https://i.stack.imgur.com/nzptp.png" alt="Add Relations Tab - SQL Server Compact Tool Box"></p>\n'}, {'answer_id': 26601080, 'author': 'Alex Jolig', 'author_id': 2263683, 'author_profile': 'https://Stackoverflow.com/users/2263683', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/vstudio/bb546200%28v=vs.100%29.aspx" rel="nofollow">Walkthrough: Creating a SQL Server Compact 3.5 Database</a></p>\n\n<p>To create a relationship between the tables created in the previous procedure</p>\n\n<ol>\n<li>In Server Explorer/Database Explorer, expand Tables.</li>\n<li>Right-click the Orders table and then click Table Properties.</li>\n<li>Click Add Relations.</li>\n<li>Type FK_Orders_Customers in the Relation Name box.</li>\n<li>Select CustomerID in the Foreign Key Table Column list.</li>\n<li>Click Add Columns.</li>\n<li>Click Add Relation.</li>\n<li>Click OK to complete the process and create the relationship in the\ndatabase.</li>\n<li>Click OK again to close the Table Properties dialog box.</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/46827', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1943/']