存储过程 插入数据时判断是否有该记录,如果有则更新该记录没有则插入该数据,各位帮帮忙我急着用 谢谢了!

解决方案 »

  1.   


    create proc dbo.过程名
    @参数1 int, --主键
    @参数2 nvarchar(20)
    as
    declare @recordcount int
    select @recordcount=(select count(*) from 表名 where 主键=@参数1)
    if(@recordcount=0)
        insert into  表名 .......
    else
        Update 表名 set ...
      

  2.   


    Create Proc dbo.过程名
    @ID int, --主键
    @参数 nvarchar(32)
    as
    if exits(select 1 from 表名 where ID=@ID)
        Update 表名 set ...
    else
        insert into  表名 .......