adspace


How to write query to Delete the records in child table
and corresponding records in parent table

Answer Posted / krishna evsg

With help of temporary tables , we can do it made easy

create table #temp_ParentIDs
(
ID int
)
GO

Insert into #temp_ParentIDs
(ID)
select Parent_id from child_tab
GO

delete from Child_tab
GO

delete from parent_tab where parent_Id In(select * from
#temp_ParentIDs)
GO

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between upgrade and migration in sql server?

1186


How to convert character strings into numeric values?

1194


Is there any performance difference between if exists (select null from table) and if exists (select 1 from table)?

1025


What is subquery? Explain the properties of a subquery?

1064


What is sql server query analyzer?

1135


If you're given a raw data table, how would perform etl (extract, transform, load) with sql to obtain the data in a desired format?

1049


What are the risks of storing a hibernate-managed object in a cache? How do you overcome the problems?

1202


How can we solve concurrency problems?

1124


What is temporary table in sql server? Why we use temp table?

1024


How to provide default values to function parameters?

1264


What is acid mean in sql server?

1248


What are the properties of the transaction?

1075


Can one drop a column from a table?

1093


How to convert numeric expression data types using the cast() function?

1155


What is standby servers? Explain types of standby servers.

1085