Click here to Skip to main content
15,923,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is this possible in an sql database?

balance table
pk balanceid
fk payid

payment table
pk payid
fk balanceid
Posted
Comments
_Zorro_ 6-Sep-11 12:11pm    
Just out of curiosity, what would be the point of doing that? I can't picture any scenario where I would need such design.

Yes (if both balanceid in balance table and payid in payment table satisfy primary key requirements).
We call it 'double linked list'. :-)
 
Share this answer
 
Comments
Wendelius 6-Sep-11 11:39am    
Good answer, my 5 Just minor note: those key columns must be either primary keys or unique keys :)
Yes this is possible. And as CPallini noted the PK must mean ether primary key or unique key.

However, this may not be the best design. Depending on the situation this may lead to multiple statements, for example first insert to payment, get the new payid and then update the balance table.

If the function of the payid in balance table is just to inform the latest payment, consider adding a time or identity information to payment so that you can always fetch the latest (or second or third...) payment without having to maintain the foreign key.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900