存储过程中"SET NOCOUNT ON"的用处,我想返回影响的行数啊,但我的设计正确吗?
SETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGOCREATEPROCEDUREgroup_add@用户IDbigint,@分组名ncha...
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE group_add
@用户ID bigint,
@分组名 nchar(10)
AS
IF(NOT EXISTS(SELECT * FROM [group] WHERE 用户ID = @用户ID AND 分组名 = @分组名))
BEGIN
SET NOCOUNT ON;---------------------------
INSERT INTO [group] VALUES(@用户ID,@分组名)
END
如上一个存储过程,我想在执行此存储过程后返回insert操作所影响的行数(1或0),但是不是要把SET NOCOUNT ON改为SET NOCOUNT OFF ?
我在.cs文件下使用C#语言编写调用此存储过程的方法,部分如下:
string strCommand = "EXEC group_add " + "100" + "," + "'好友'";
SqlCommand objCommand = new SqlCommand(strCommand);
SqlConnection objConnection = new SqlConnection(strConnect);
objCommand.Connection = objConnection;
objConnection.Open();
int num = objCommand.ExecuteNonQuery();
如果存储过程中的insert操作成功,在(SET NOCOUNT OFF)下,num是不是==1 ?
在(SET NOCOUNT ON)下,num是不是==0 ? 展开
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE group_add
@用户ID bigint,
@分组名 nchar(10)
AS
IF(NOT EXISTS(SELECT * FROM [group] WHERE 用户ID = @用户ID AND 分组名 = @分组名))
BEGIN
SET NOCOUNT ON;---------------------------
INSERT INTO [group] VALUES(@用户ID,@分组名)
END
如上一个存储过程,我想在执行此存储过程后返回insert操作所影响的行数(1或0),但是不是要把SET NOCOUNT ON改为SET NOCOUNT OFF ?
我在.cs文件下使用C#语言编写调用此存储过程的方法,部分如下:
string strCommand = "EXEC group_add " + "100" + "," + "'好友'";
SqlCommand objCommand = new SqlCommand(strCommand);
SqlConnection objConnection = new SqlConnection(strConnect);
objCommand.Connection = objConnection;
objConnection.Open();
int num = objCommand.ExecuteNonQuery();
如果存储过程中的insert操作成功,在(SET NOCOUNT OFF)下,num是不是==1 ?
在(SET NOCOUNT ON)下,num是不是==0 ? 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询