I allow the user to delete record1 from SQL Table1 and record2 from Table2. The only problem is, record1 and record2 refers to record3 in Table3 and I can′t allow the user to delete record1 if the is a field in record3 with record1 ref. code. I can′t set FK between them cuz there is more than one reference to the same field.
Can someone point the best solution for my problem?
Hope I'm not getting the tables mixed up, but try this:
Table 3 is a "parent" of table1, meaning that every row in table1 must have a matching ref code in table3 (iow, you can't delete a row in table3 if there's a matching ref code in table1)
alter table Table1
add constraint FK_Table1RefCode
foreign key (RefCode)
references Table3(RefCode)
Same goes for table2:
alter table Table2
add constraint FK_Table2RefCode
foreign key (RefCode)
references Table3(RefCode)
I hope I understood your question!
|||That almost right, codefield1 Table1 and codefield2 Table2 and must ref. the same codefield in Table3(Parent Table); Table1 and 2 both have only two fields. I already added the constraints but Visual C# shows an error message when Insertin'
|||Mr.Rezende:
Visual C# shows an error message when Insertin'
What's the error?
Also, please post your DDL
No comments:
Post a Comment