adspace


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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

what are the advantages of sql ? : Sql dba

1154


How do I remove duplicates in two columns?

1202


what is collation? : Sql dba

1242


what are all the common sql function? : Sql dba

1141


what is schema? : Sql dba

1163


what is bcp? When does it used? : Sql dba

1065


how to use regular expression in pattern match conditions? : Sql dba

1125


how to escape special characters in sql statements? : Sql dba

1124


Can we use distinct and group by together?

1147


If a cursor is open, how can we find in a pl/sql block?

1252


What is your daily office routine?

2353


what is dbms? : Sql dba

1070


Does group by remove duplicates?

1121


what is sql server agent? : Sql dba

1189


Can we rollback truncate?

1083