Solved

Relation question

Posted on 2006-11-20
6
214 Views
Last Modified: 2012-06-21
I have the following tables

table1
AssetID (primary key)
Name

table2
CorID (primary key)
AssetIDx
AssetIDy

now I want a relation from assetsIDx in table2 to assetID in table1 AND
I want a relation from assetsIDy in table2 to assetID in table1

how ???
0
Comment
Question by:RonaldBiemans
6 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 42 total points
ID: 17978882
do you mean create 2 foreign keys, one for AssetIDx pointing to AssetID and the second AssetIDy pointing to the same field?

or do you want to build a query, to return the 2 different Asset Names ?

select t2.*, a1.Name Asset1, a2.Name asset2
from Table2 t2
left join table1 a1
  on a1.assetid = t2.AssetIDx
left join table1 a2
  on a2.assetid = t2.AssetIDy
0
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 41 total points
ID: 17978899
ALTER TABLE table2 ADD CONSTRAINT FK_table2 FOREIGN KEY
      (
            [AssetIDx]
      ) REFERENCES [table1] (
            [AssetID]
      )
0
 
LVL 25

Author Comment

by:RonaldBiemans
ID: 17978926
No I do not want to create a query, I want to create 2 foreign keys
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 25

Author Comment

by:RonaldBiemans
ID: 17978946
gauthampj that works for one but not for both, hence my question
0
 
LVL 28

Accepted Solution

by:
imran_fast earned 42 total points
ID: 17978983
you neet to create two references

ALTER TABLE table2 ADD CONSTRAINT FK_table2_AssetIDx FOREIGN KEY
     (
          [AssetIDx]
     ) REFERENCES [table1] (
          [AssetID]
     );

ALTER TABLE table2 ADD CONSTRAINT FK_table2_AssetIDy FOREIGN KEY
     (
          [AssetIDy]
     ) REFERENCES [table1] (
          [AssetID]
     );
0
 
LVL 25

Author Comment

by:RonaldBiemans
ID: 17979045
PFFFFFFFF,  I'm stupid sorry,  I had already done what you all suggested and it didn't work because I had another reference (which I didn't mention) set to cascading Update/Delete if I remove that it works.

I'll just distribute the points to everybody that commented, sorry to have waisted your time :=)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now