Is it possible to remove child records without removing master table records...the two having pk,fk relationship?



Is it possible to remove child records without removing master table records...the two having pk,fk..

Answer / Devendra Pratap Singh

In SQL and PL/SQL, it is possible to delete child records while keeping the master table records intact by using a technique called 'Cascading Delete'. However, this operation needs to be explicitly defined in the foreign key constraint. If cascading delete is not defined, you can use a DELETE statement with a JOIN to remove only the child records. Here's an example of how it might look like for a SQL DELETE operation:

```sql
DELETE c
FROM ChildTable c
JOIN MasterTable m ON c.FK_MasterId = m.PK_MasterId
WHERE condition;
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

What are Global Temporary tables

3 Answers   IBM, TCS,


Is sql difficult?

1 Answers  


What is dba in sql? : SQL DBA

1 Answers  


What is restrict in sql?

1 Answers  


What is ttitle and btitle?

1 Answers  


what is the difference between char and varchar data types? : Sql dba

1 Answers  


Explain normalization and what are the advantages of it?

1 Answers  


Suppose I have to create a view on a table, that is not yet been created by DBA. I khow the table structure. Is it possible to create the view before DBA creates this table? If yes then how? Is it possible to create synonym in this way?

4 Answers   IBM, Metric Stream,


C. Normalize the following data up to the 3rd Normal form. Create the tables and insert the data given. Emp_ID Name Dept_Name Salary Course_Title Date_Completed 100 Adam Marketing 48,000 SPSS 6/19/2008 Surveys 10/7/2008 140 Bob Accounting 52,000 Tax Acc 12/8/2008 110 Cathy IT SQL Server 1/12/2008 C# 4/22/2008 190 Dan Finance 150 Emily Marketing 55,000 SPSS 6/16/2008 42,000 Analysis 8/12/2008 Queries 1. Find all Names who have completed the SPSS Course. 2. Find employee with max salary. 3. Find employee with 2nd max salary. 4. Find all employees in Dept “Marketing”. 5. Find all the employees who have taken more than 2 courses. 6. Find all the employees who have completed the courses before month of September.

1 Answers  


what is the cursor and use of cursor in pl/sql ?

4 Answers  


What is sharding in sql?

1 Answers  


What are hotfixes and patches?

1 Answers  


Categories