1

I do not really know whether this is logically feasible but I have a table:

PERSON: Id (PK), Name, SoldTo (FK), ShipTo (FK), BillTo (FK) ADDRESS: AddrId (PK), Street, Number, Town, Type 

Type in ADDRESS will contain a string describing the address type. I would like to link SoldTo, ShipTo and BillTo to AddrId. Of course they can also point at the same record.

However in SSMS it forbids me to do that.

Anybody knows a workaround or a better way to do it? Thanks

UPDATE

In order to see what I mean with "SSMS forbids me to do that" have a look at the screenshot in the link below. Consider CMF_ContactInfo as ADDRESS and CMF_AccountInfo as PERSON. As you can see I can add ContactId to the relationship just once...

SSMS Tables and Columns Dialog

1
  • 2
    Why does SSMS forbid you to do this?? Can you show us what you're trying to do (in T-SQL) ?? Do you get errors - if so: what errors exactly?? Commented Dec 7, 2011 at 16:31

2 Answers 2

4

Don't know how you are trying to do that in SSMS (possibly you are trying some interactive tools, I know little about them), but this is how you can do what you want in plain Transact-SQL:

CREATE TABLE Address ( AddrId int CONSTRAINT PK_Address PRIMARY KEY, Street varchar(50), Number int, Town varchar(50), Type int ); CREATE TABLE Person ( Id int PRIMARY KEY, Name varchar(100), SoldTo int NOT NULL CONSTRAINT FK_Address_SoldTo FOREIGN KEY REFERENCES Address (AddrId), ShipTo int NOT NULL CONSTRAINT FK_Address_ShipTo FOREIGN KEY REFERENCES Address (AddrId), BillTo int NOT NULL CONSTRAINT FK_Address_BillTo FOREIGN KEY REFERENCES Address (AddrId) ); 

Not sure about the actual types, but you get the idea. Also you might want to drop NOT NULL where it is not needed (or add it where necessary).

Sign up to request clarification or add additional context in comments.

3 Comments

+1 exactly - there should not be any problem creating three FK relations from Person to Address using those columns....
+1 to Andriy. My question to @CiccioMiami: It seems like someone is selling, shipping (and billing for) persons. Has slavery been re-legalized in Miami?
Ahaha, good one! It was just an example. See the screenshot in the question update. Thanks
2

You have to add multiple relationships ! (with different names) Just like if it were different tables.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.