บันทึกการแก้ปัญหาแบบหมูๆ
Group Blog
 
All Blogs
 

SET NOCOUNT ON ใน Stored Procedure ช่วย performance ระบบได้

คำสั่ง SET NOCOUNT ON เป็นการ "หยุด" การคืนค่า จำนวนบรรทัดที่ได้จากการ Select ของ SQL Server มาให้ผู้เรียก

ผลของการหยุด COUNT นี้ ทำให้การคืนค่า หายไป แต่ผลพลอยได้คือ ระบบเร็วขึ้น และไม่รบกวนการ nest call ของ stored procedure (จากเรื่อง "Crystal Report ... ทำไม ข้อมูลไม่ออกฟะ"

แต่ถ้าเรายังต้องการจำนวนบรรทัดที่ได้จากการเรียก procedure ก็สามารถใช้ตัวเลือก @@ROWCOUNT ได้อยู่ แม้จะ SET NOCOUNT ON ไปแล้วก็ตาม

ใน SQL Server 2005 ของ Microsoft เวลาเราสั่งสร้าง Procedure ใหม่ มันใส่ SET NOCOUNT ON มาให้เลย (ของ 2000 ไม่มีมาให้) ดังตัวอย่าง

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
CREATE PROCEDURE
-- Add the parameters for the stored procedure here
<@Param1, sysname, @p1> = ,
<@Param2, sysname, @p2> =
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO




 

Create Date : 28 มกราคม 2552    
Last Update : 28 มกราคม 2552 1:54:34 น.
Counter : 4284 Pageviews.  

Crystal Report ... ทำไม ข้อมูลไม่ออกฟะ

ตอน Preview ทำไม Preview ได้ 100%
แต่พอเรียกจากโปรแกรม (vb.net) กลับไม่แสดงข้อมูลใดๆ โล่งตลอด ?


ปัญหา และสาเหตุ


อ้อ! ปัญหาคือ Report ตัวนี้ เรียกใช้ Stored Procedure ไม่ใช่เท่านั้น ใน Stored Procedure ใช้โครงสร้าง Temp Table ไม่ใช่เท่านั้น (อีกครั้ง) ยังมีการเรียก Stored Procedure ซ้อนอีกชั้นนึงอีก ...


งมอยู่หลายชั่วโมง ในที่สุด ก็พบข้อมูลใน Web บอกว่า ให้ SET NOCOUNT ON สิ


ลองใส่ SET NOCOUNT ON หลังคำว่า Begin เท่านั้น แหละ ใช้ได้เลย


ว่าแต่ว่า NOCOUNT นี่มันอะไรกัน Smiley


 






Free TextEditor




 

Create Date : 27 มกราคม 2552    
Last Update : 27 มกราคม 2552 1:34:49 น.
Counter : 1704 Pageviews.  


หมูกระแทก
Location :


[Profile ทั้งหมด]

ให้ทิปเจ้าของ Blog [?]
ฝากข้อความหลังไมค์
Rss Feed

ผู้ติดตามบล็อก : 1 คน [?]


ผู้ติดตามบล็อก : 1 คน [?]




Friends' blogs
[Add หมูกระแทก's blog to your web]
Links
 

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.