Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Relation question

Posted on 2006-11-20
6
Medium Priority
?
222 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 168 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 164 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
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 168 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

705 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