Solved

Relation question

Posted on 2006-11-20
6
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

632 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