感謝您看看這個。插入選擇後SQL Server掛起
該問題與以下sql查詢有關。基本上,它會遞歸地查找某個頁面(母版頁)下的所有頁面,然後將母版頁的類別(在xref_pages_categories中查找)應用於所有這些頁面。
在運行插入時,查詢表應該已完全插入的數據掛起。
如果我不跑了插入線查詢,結果回來完美,如:
3245 490
3249 490
3252 490
但在把刀片在它的前面和插入,查詢的pageid = 3245只是掛起。有任何想法嗎?
declare @page int;
set @page=3202;
begin transaction transki;
With FindAllPagesUnderneath(PageID, ParentID) as
(
select id as PageID, ParentPageId as ParentID
from pages where [email protected]
union all
select id as PageID, ParentPageID as ParentID
from pages p
inner join FindAllPagesUnderneath mp on
p.parentpageid=mp.PageID
)
insert into xref_pages_categories (PageID, CategoryID)
--get records that definitely arent already in xref_pages_categories
select * from
(
select distinct thegood.*
from
(
--get all pages under @page attached to new categoryid
select distinct fap2.PageID, fapo.CategoryID
from FindAllPagesUnderneath fap2
cross join (
select fap.PageID,xpc.categoryid
from xref_pages_categories xpc
inner join FindAllPagesUnderneath fap
on fap.PageID=xpc.pageid
where fap.pageid!=1 and
fap.pageid!=1332
and fap.parentid=1332
) fapo
where fap2.pageid [email protected]
) thegood
left outer join xref_pages_categories xpc
on xpc.pageid = thegood.pageid
where xpc.pageid is null
) final
您沒有在您的示例中提交事務。該示例中的錯誤還是錯誤錯誤? –
2010-03-03 14:41:14
我相信答案,因爲當我沒有提交臨時表時,它在 – Micah 2010-03-03 19:58:23