Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

MSDE create a relationship error on pc.

I have installed the MSDE on my laptop (windows XP SP2) and created a new database and some tables. I have an identity field as the Primary Key in all tables. But I cannot create a relationship between any tables. The popup error message is "The columns in the table 'A' do not match an existing primary key or unique constraint". Table "A" has a primary key field so what am I doing wrong?
[400 byte] By [PineTree] at [2007-11-11 7:33:48]
# 1 Re: MSDE create a relationship error on pc.
Please post the structure of your tables and describe how you would like to relate them.
Phil Weber at 2007-11-11 23:47:48 >
# 2 Re: MSDE create a relationship error on pc.
I am just getting started with an address table which contains an identity field called ADDRESS_SID. This table will contains all the addresses for persons, businesses, and other objects. I created another table called ADDRESS_LINKS which has four fields:

ADDRESS_LINK_SID 'The identity field for the table
ADDRESS_LINK_TYPE_SID 'A foreign key field to ADDRESS_LINK_TYPES table
ADDRESS_OBJ_SID 'The foreign key to the PERSONS table
ADDRESS_SID 'The foreign key to the ADDESSES table

The ADDRESS_LINKS_TYPES table has two fields:

ADDRESS_LINK_TYPE_SID 'The identity field
ADDRESSLINK_TYPE_NAME 'The text name such as PERSON or BUSINESS

I, therefore, am trying to create a relationship in the ADDRESS_LINKS table to
the ADDRESS_LINKS_TYPES table with the ADDRESS_LINK_TYPE_SID field
in each table but the error message says there is no unique field in the ADDRESS_LINKS_TYPES table.

I get the same error when I try to create a relationship to the ADDRESS table.
Could it be that the desktop version does not allow relationships? Thanks for your help and hope you are having a good holiday season.
PineTree at 2007-11-11 23:48:48 >
# 3 Re: MSDE create a relationship error on pc.
MSDE does support relationships. You say that your tables each have a primary key, but the error message in your initial post indicates that they do not. How are you creating your tables: SQL Enterprise Manager, or SQL statements? If you're using Enterprise Manager, when you open each table in Design view, do you see a primary key symbol (a little yellow key) next to the identity column? If you're using SQL statements, have you executed a statement like the following on each table?

ALTER TABLE [dbo].[ADDRESS] ADD CONSTRAINT [PK_ADDRESS] PRIMARY KEY
( [ADDRESS_SID]
) ON [PRIMARY]
Phil Weber at 2007-11-11 23:49:52 >
# 4 Re: MSDE create a relationship error on pc.
I am using the server view in Visual Studio .Net 2003. I am writing a C# program and simultaneously using VS to create the tables and relationships.
PineTree at 2007-11-11 23:50:54 >
# 5 Re: MSDE create a relationship error on pc.
OK, you didn't answer my question about whether you see a primary key symbol (a little yellow key) next to the identity columns.
Phil Weber at 2007-11-11 23:51:53 >
# 6 Re: MSDE create a relationship error on pc.
Yes. The table designs look good. I can add data via the Visual Studio table data views and I can see the primary key symbol next to the identity columns in design view. When I right mouse click over the table in design view, I get the form with the relationships, constraints, etc. When I select the Relationships tab and I select the the tables and columns to join, I get the error message as soon as I try to change the name of the relationship or try to save.
PineTree at 2007-11-11 23:52:52 >
# 7 Re: MSDE create a relationship error on pc.
I had the same issue and got over it by un-setting the primary key and re-creating it in Enterprise Manager - the relationship worked immediately. I suspect something to do with the create script I used to make the table
JohnM at 2007-11-11 23:53:51 >
# 8 Re: MSDE create a relationship error on pc.
I found my own mistake. I had the tables reversed in the relationships dialog form. Thanks for the help anyway.
PineTree at 2007-11-11 23:54:54 >