Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-01-07 : 08:03:14
|
| HiIs it possible to refer a single column from two different tables of same datatype.I create a Client table (Clientcode is a primary key)I create a Account table (Acctcode is a primary key)One more table AcctTran(Here AcctCode is the same datatype of Client or Account table)I want to refer this AcctCode from AcctTran refer the (ClientCode and AcctCode) from Client and Account tableI create like theseForeign Key (AcctCode) References ClientMast(ClientCode),Foreign Key (AcctCode) References AcctMast(AccountCode),While inserting records its shows error as below:Msg 547, Level 16, State 0, Line 1INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK__AcctTran__AcctCo__32E0915F'. The conflict occurred in database 'Babu', table 'ClientMast', column 'ClientCode'.The statement has been terminated.kindly suggest relate this |
|
|
pootle_flump
1064 Posts |
Posted - 2008-01-07 : 08:41:10
|
| Is your problem that transactions may be made by Accounts or by Clients? If so you can create a single table for Clients and Accounts and have nullable columns in there. There are other methods too (including using triggers for integrity rather than Declaritive stuff) but that is an easy option. You would have to ensure, however, that a client and an account could never share a PK value.HTH |
 |
|
|
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-01-07 : 08:56:03
|
| Thanks for your reply. I too get the same from SQL Help |
 |
|
|
|
|
|