Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with creating relationships

Author  Topic 

Darkmatter5
Starting Member

17 Posts

Posted - 2012-11-19 : 11:20:39
I have two table both with a column named TypeID.

Paths <-table
TypeID (int, 4, primary key = no, identity = false)

Types <-table
TypeID (int, 4, primary key = yes, identity = true)

This is a SQL compact DB that I'm editing through Visual Studio. When I try and make a relationship between the two tables via the TypeID columns I get the following error.

"Add Relation failed. Parent Columns and Child Columns don't have type-matching columns."

Both are int with length 4, what could be causing this error?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2012-11-19 : 11:56:01
I don't have too much to offer here but since no one else is chiming in -
Perhaps VS's schema is out of sync with the actual database or maybe pointing to a different db instance?

But being a long term sql server developer I only use Management Studio for this. For instance to create this "relationship" I would use a query window to issue this command:

alter table Paths add constraint FK_Paths_Types foreign key (TypeID) references Types (TypeID)

Can Sql Compact be used in SSMS?

Be One with the Optimizer
TG
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-11-19 : 12:54:29
I think it might be due to identity column. Do you have some value in child table(Primary Key) which doesn't exist in Parent table?
Go to Top of Page
   

- Advertisement -