Solved

Relation question

Posted on 2006-11-20
6
213 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

744 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

13 Experts available now in Live!

Get 1:1 Help Now