本文介绍了如果记录已经存在,请停止在表中插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ALTER PROCEDURE [dbo]。[uspInsertDelegate]
(
@CourseID int,
@CPUserID int,
@StatusID int,
@CreateUser varchar(25)
)
AS
SET NOCOUNT OFF;
INSERT INTO tblDelegate
(
CourseID,
CPUserID,
StatusID,
CreateUser
)
VALUES
(
@CourseID,
@CPUserID,
@StatusID,
@CreateUser
)
RETURN
现在我不想插入表 tblDelegate ,如果插入 courseid 和 cpuserid 与表tblDelegate中的记录相同
解决方案
先测试。在SQL Server 2005中,您也可以TRY / CATCH忽略重复错误。
IF NOT EXISTS(SELECT *
FROM tblDelegate
WHERE CourseID = @CourseID等)
INSERT INTO tblDelegate
(
CourseID,
CPUserID,
StatusID,
CreateUser
)
VALUES
(
@CourseID,
@CPUserID,
@StatusID,
@CreateUser
)
我可以问:你的意思是SET NOCOUNT ON?
I have sql server procedure, please see below.
ALTER PROCEDURE [dbo].[uspInsertDelegate]
(
@CourseID int,
@CPUserID int,
@StatusID int,
@CreateUser varchar(25)
)
AS
SET NOCOUNT OFF;
INSERT INTO tblDelegate
(
CourseID,
CPUserID,
StatusID,
CreateUser
)
VALUES
(
@CourseID,
@CPUserID,
@StatusID,
@CreateUser
)
RETURN
Now I don't want to insert into table tblDelegate if the inserting courseid and cpuserid is same for that records in table tblDelegate
解决方案
Simply test first. In SQL Server 2005 you could also TRY/CATCH to ignore a duplicate error.
IF NOT EXISTS (SELECT *
FROM tblDelegate
WHERE CourseID = @CourseID etc)
INSERT INTO tblDelegate
(
CourseID,
CPUserID,
StatusID,
CreateUser
)
VALUES
(
@CourseID,
@CPUserID,
@StatusID,
@CreateUser
)
May I ask: do you mean "SET NOCOUNT ON"?
这篇关于如果记录已经存在,请停止在表中插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!