create PROCEDURE p_setTitle @title varchar(200) as if not exist(select * from table1 where title='一二三') begin insert into talbe1 (title) values (@title) end go
Sorry: create PROCEDURE p_setTitle @title varchar(200) as if not exist(select * from table1 where title=@title) begin insert into talbe1 (title) values (@title) end go
使用函数不就行了! 当有重复记录,返回false; 插入记录成功,就返回true.
增加一个返回值不就可以判断添加结果了吗 create PROCEDURE p_setTitle @title varchar(200) as if not exist(select * from table1 where title=@title) begin insert into talbe1 (title) values (@title) return(0) --成功 end else begin return(1) --数据重复 end if @@error > 0 begin return(2) --失败 end go
if not exist(select * from table1 where title='一二三') begin insert into talbe1 (title) values (@title) end
@title varchar(200)
as
if not exist(select * from table1 where title='一二三')
begin
insert into talbe1 (title)
values (@title)
end
go
create PROCEDURE p_setTitle
@title varchar(200)
as
if not exist(select * from table1 where title=@title)
begin
insert into talbe1 (title)
values (@title)
end
go
当有重复记录,返回false;
插入记录成功,就返回true.
create PROCEDURE p_setTitle
@title varchar(200)
as
if not exist(select * from table1 where title=@title)
begin
insert into talbe1 (title) values (@title)
return(0) --成功
end
else
begin
return(1) --数据重复
end
if @@error > 0
begin
return(2) --失败
end
go
begin
insert into talbe1 (title)
values (@title)
end