Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / arijitnit

delete from child_table where values=...
on delete cascade..
U have to set the foreign key as the parent super key

Is This Answer Correct ?    11 Yes 7 No

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

Answer / dileep

Better you create a Trigger on child table like this one

CREATE TRIGGER trDelTrigger ON [dbo].[ChildTable]
FOR DELETE
AS
DELETE FROM ParentTable WHERE ParentTable.IdColumn=
(SELECT Deleted.IdColumn FROM Deleted)

Is This Answer Correct ?    9 Yes 5 No

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

Answer / 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

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

Answer / krishnakumar

create table employee(id int references authors(au_id) ON
DELETE CASCADE,firstname(30))



this is chilld table .in this query use on first child table
constraints values delete next parent table constrains value
delete ... this is ON DELETE CASCADE CONCEPT

Is This Answer Correct ?    7 Yes 5 No

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

Answer / chaitanya

***********
Delete from P_table where P_Id=C_Id
***********

This is only aplicable if you have defined the foreign key
in the child table with the constraint on Delete Cascade.
Else you will get a Integration error.

Is This Answer Correct ?    1 Yes 0 No

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

Answer / satyanarayana

I think using ON DELETE CASCADE we can delete the records
from both child and parent table

Is This Answer Correct ?    4 Yes 4 No

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

Answer / tester

Hi vaishali have u executed the query it is not working

Is This Answer Correct ?    6 Yes 9 No

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

Answer / surya

use this:

DELETE FROM childTable WHERE EXISTS(SELECT id FROM
parentTable WHERE parentTable .id = childTable .id where id = 1)

Is This Answer Correct ?    4 Yes 7 No

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

Answer / sanjay

delete details from details inner join master on
details.keyid=master.keyid

Is This Answer Correct ?    0 Yes 4 No

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

Answer / zackziss

delete from c from child c inner join parent
on c.childid = parentid

Is This Answer Correct ?    2 Yes 11 No

Post New Answer

More SQL Server Interview Questions

How to enter binary string literals in ms sql server?

0 Answers  


What is the openxml statement in sql server?

0 Answers  


When do you think a developer should use sql server-based cursors?

0 Answers  


Is foreign key a primary key?

0 Answers  


What happens if null values are involved in string operations?

0 Answers  


What are the properties of the transactions?

0 Answers  


Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?

0 Answers  


How to create a stored procedure with a statement block in ms sql server?

0 Answers  


how to dispaly a particular row details from a given table

2 Answers  


UPDATE statement can on a single table or on the multiple table?

7 Answers   iGate, TCS,


Find top Nth employee from each department in terms of salary?

13 Answers   RealPage,


difference between function and procedure

3 Answers   Cognizant, HCL, TCS, Theorem,


Categories