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

between cast and convert which function would you prefer and why?

727


How extra digits are handled with numeric data type literals?

693


You want to check the syntax of a complicated update sql statement without executing it. What command should you use?

677


How to use column default values in insert statements in ms sql server?

716


What is compound operators?

709






Can group by be used without aggregate functions?

677


Explain Geometry datatype in sql server 2008 with example

751


Explain Geography datatype in SQL Server

805


What are binary string data types in ms sql server?

817


What is a transact-sql statement batch in ms sql server?

670


What are user-defined functions (udfs) in sql server?

731


How many levels of sp nesting is possible?

795


Show Practically Sql Server Views are updatable?

785


What is auditing in sql server?

685


How to return the second 5 rows in ms sql server?

787