您的位置:首页 > 其它

利用存储过程判断添加记录不能重复

2008-09-21 20:02 288 查看
如果存在相同类型相同名称的记录则不能添加

CREATE proc QsqPageContentInsertUpdateDel

(  

@id int=0 out ,  

@ObjectID int=null,

@Type varchar(50)=null,

@ShowType varchar(50)=null,

@ShowName varchar(500)=null,

@OrderBy int=null,

@action int=0 --1 insert   2 update  3delete

)  

  

AS  

  

IF @action = 1  

BEGIN  

    if not exists (select * from QsqPageContent where ObjectID=@ObjectID and  ShowType=@ShowType)

    begin

        INSERT INTO QsqPageContent(

        [ObjectID],[Type],[ShowType],[ShowName],[OrderBy]

        )VALUES(

        @ObjectID,@Type,@ShowType,@ShowName,@OrderBy

        )

        SET @id = @@IDENTITY

    end

END  

else if  @action = 2  

BEGIN  

    UPDATE QsqPageContent SET 

    [ShowName] = @ShowName,[OrderBy] = @OrderBy

    WHERE ID=@id 

END  

else if  @action = 3 

BEGIN  

    DELETE QsqPageContent

     WHERE ID=@id 

END

GO
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: