sql 更新遞歸數據

declare @foladID nvarchar(500)
set @foladID='DCAE7E1B-266F-40B0-AA4B-97EBD334A25D';
with tab as(
select *  from Folders  where id=@foladID
union all 
select k.* from Folders k 
 inner join tab c on k.id = c.Parentid
 )
 select * into #tab  from tab
--不包括本身
  update Folders  set Folders.FolderCount=Folders.FolderCount+1 from #tab where Folders.Id=#tab.Id and Folders.Id!=@foladID
  drop table #tab

 

Trashed 能夠換成臨時表,因爲個人數據是分紅了2個表全部代碼有點繁瑣sql

相關文章
相關標籤/搜索