March 4, 2006 at 4:11 am
Hi ,
I wants to delete a single record from
my master table and again insert it with
the same primary key values
but a related child table is also there so
what can i do, that i can delete
the record from master table than again
insert it...
Plz Help me out
March 6, 2006 at 2:36 am
March 6, 2006 at 5:52 am
Hi Newbie,
Just adding to wt Deepak has mentioned. Disable the constraint first, then copy the row into one more table. Delete this row.
Incase your primary key field happens to be an 'Identity column', then you need to run this command before inserting the values into the master table. This will allow you to explicitly specify values for your identity field.
Set Identity_insert <table name> On
go
run the above two lines. Once this is executed sucessfully, you can insert the record with the original value which you have.
Scorp
March 6, 2006 at 9:46 am
It is hard to make a recommendation without knowing what you are trying to accomplish.
You could DELETE the matching records from the child table first, this would allow you to DELETE the row from your master table.
OR, since you want to DELETE and then reinsert the same keyed value, you can use UPDATE to modify all the fields EXCEPT the primary key field, this would accomplish the same effect with less work.
March 6, 2006 at 12:24 pm
I agree with Ryan, why not just do an UPDATE on the table?
March 6, 2006 at 6:38 pm
I also agree.. Insert into a dummy table, then do an update on your main table joining to the dummy table.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply