sql server - delete all the child rows in sql table by parentid -


i have table create tree multiple levels , parents. table structure looks this.

enter image description here

when delete "titleid", want children , grandchildren deleted. easiest way such in sql. if simple delete "where parentid=titleid", children level 1 depth deleted.

declare @titleid int   select @@titleid = 2   ;with results as(          select  titleid            mytable            titleid = @titleid          union          select  t.titleid             mytable t                  inner join ret r on t.parentid = r.titleid )   delete mytable titleid in (select titleid    results ) 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -