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
Solved

Relation question

Posted on 2006-11-20
6
216 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 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

861 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