April 7, 2010 at 1:07 am
I have two tables.
Table1:
EngineerId,
EngineerName,
DeptId,
ProjectId
Table 2:
EngineerId
PFNO
ContactNo
MailId
Suppose if this is the case, If I remove the EngineerId column in Table1, that delete should applicable to the Table2 also.
Please give a code for this with atleast minimum explanation? I am using CASCADE this is the first time.
April 7, 2010 at 4:23 am
ALTER TABLE [dbo].[table1] WITH CHECK ADD FOREIGN KEY([fieldid])
REFERENCES [dbo].[table2] ([fieldi_id])
ON DELETE CASCADE
April 7, 2010 at 4:29 am
Can you please explain this code little bit?
April 7, 2010 at 5:16 am
chandrasekaran.ganapathy (4/7/2010)
Can you please explain this code little bit?
Links:
Cascading Referential Integrity Constraints
Post back if you have any questions.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 7, 2010 at 9:24 am
Say Eg :
Table1
FieldId FieldName
1 Value1
2 Value2
3 Value3
Table2
TbkPk FieldId FieldName2
1 1 Value12
2 1 Value23
3 2 Value34
If Table2.FieldId is foregin keyof table1.FieldId and if we have casecade delete between these two field, when we delete the FieldId '1' from table1 will automatically delete FieldId '1' in Table2 (ie 2 record with fieldid=2)
April 7, 2010 at 5:55 pm
rvasanth (4/7/2010)
If Table2.FieldId is foregin keyof table1.FieldId and if we have casecade delete between these two field, when we delete the FieldId '1' from table1 will automatically delete FieldId '1' in Table2 (ie 2 record with fieldid=2)
It can be set up to work that way, yes.
Why don't you try an experiment?
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
April 7, 2010 at 11:22 pm
It means that table2 has multiple instance of fieldid (say eg. fieldid =2). If you delete filedid (fieldid 2)then all the fieldid 2 will be deleted in table 2 right?
April 8, 2010 at 10:58 am
exactly
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply