We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,608 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to relate 2 foreign columns of same table with one primary column...

I have an sql table that stores English words and second table that stores meanings of those words in related maner.
Here are some informations about table structures:

Table1 name: Words
WordID int IDENTITY(1,1) NOT NULL, //This is primaryKey
Word varchar(50) NOT NULL,

Table2 name: Meanings
MeaningID int IDENTITY(1,1) NOT NULL, //This is primaryKey
WordID1 int) NOT NULL, //This is foreinKey
WordID2 int) NOT NULL, //This is foreinKey

All I want is that, use the WordID from the table “Words” as the word I want to give a mening and store it in WordID1 column of the table “Meanings”. Also use the WordID from the table “Words” that corresponds to the meaning of the word I select and store it in WordID2 column of the table “Meanings” as meaning of that word.
When I try to insert the record, using sql management object, I receive a forein key conflict constranct.
So can anyone help me overcame this?
Please help!

5
Contributors
3
Replies
1 Week
Discussion Span
1 Year Ago
Last Updated
4
Views
Verygoodguy
Newbie Poster
13 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

you are trying to insert wordid in wordid1 or wordid2 which do not exites in table words

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

I agree with utrivedi. My guess is you've used the graphic environment to join the 2 tables and see only the 2 word fields and it didn't work. What you need to do is insert both words in the Words table and then insert their "relationship" in the Meanings.

adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11

I feel that a foriegn key must be a primary key to some other table.WordID is a primary key to words table ,so this column can be used as a foriegn key to meanings table where as wordid1 and wordid2 are not primary keys, so these columns can not be used as foriegn keys.

codemasters
Newbie Poster
3 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0688 seconds using 2.65MB