请问在SQLSERVER2000中如何用存储过程判断一条重复的记录并返回结果。
比如我新增一条记录到数据库的A表,但表中有相同的记录信息了,我如何让SQLSERVER告诉我表中已有重复的记录?我在delphi中该如何调用这存储过程?

解决方案 »

  1.   

    seelct * from aaa a join aaa b on a.id<b.id
    在查询分析器中执行上面的SQL看看.
      

  2.   

    最好建立约束,在添加记录的时候用
    Tryexceptend;
    结构先判断出是否出错,如果出错再判断是否因为有重复记录
      

  3.   

    create procedure [%QUALIFIER%]%PROC% @MissionID integer as
    begin
        if exists (
            select * from VRCheck where MissionID=@MissionID
            )
         begin
            update VRCheck set Updated = 1 where MissionID=@MissionID
         end
         else
         begin
            insert into VRCheck (MissionID,Passed,Updated)
                values(@MissionID,0,1)
         end
    end
      

  4.   

    SQLSERVER中好象有个什么print之类的语法可以显示出结果,是吗?
      

  5.   

    Print可以显示,数字字符串都可以一般要显示可以用select 比如select @name,
    select 1
      

  6.   


    Create Procedure pTest
    (
    @sField varchar(20),
    @iReturn  Int output
    )as
    begin
            if Exists(Select 1 from TableName where sField = @sField )
            beginend
      

  7.   


    Create Procedure pTest
    (
    @sField varchar(20),
    @iReturn  Int output
    )as
    begin
            if Exists(Select 1 from TableName where sField = @sField )
            begin
                    select @iReturn = 1
            end else
            begin
                    Select @iReturn = 0
            end
    end