1. Identify the records to delete 

EXAMPLE

SELECT SC, SE, SM, CN
FROM SMS 
WHERE DEL = 0 AND SM = 'S'
SQL


2. Run SQL statement to delete the desired classes

EXAMPLE:

UPDATE SMS 
SET DEL = 1 
WHERE DEL = 0 AND SM = 'S'
SQL


3. Run SQL statement to delete orphaned SSS records 

EXAMPLE:

UPDATE SSS 
SET DEL = 1
FROM (SELECT * FROM SMS WHERE DEL = 0) SMS
    RIGHT JOIN (SELECT * FROM SSS WHERE DEL = 0 AND SE > 0) SSS ON SMS.SC = SSS.SC AND SMS.SE = SSS.SE
WHERE SMS.SE IS NULL
SQL


4. Run SQL statement to delete orphaned SSM records

EXAMPLE:

UPDATE SSM 
SET DEL = 1
FROM (SELECT * FROM SMS WHERE DEL = 0) SMS
  RIGHT JOIN (SELECT * FROM SSM WHERE DEL = 0) SSM ON SMS.SC = SSM.SC AND SMS.SE = SSM.SE 
WHERE SMS.SE IS NULL
SQL