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. |
| |
|
|
|