Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    57

    Unanswered: Treating a unique constraint in a procedure. Custom errors.

    I have a table Table1 with three fields:
    _PK, _Unique and _Description
    The field _PK is primary key, and the field _Unique is constraint to be unique.
    The _PK is generated with a sequence. In SQL Server the procedure is something like that (using a custom error)

    create procedure Insert_Table1 (v_Unique ..., v_Description ...)
    as
    if exists (select * from Table1 where _Unique = v_Unique)
    raiserror (@Custom_error, 16, 1)
    else
    insert into TAble1 (_UNique, _Description)
    select v_Unique, v__Description

    Can you tell me please how can I translate this procedure in a db2 sql procedure? Can I define a custom error?
    Thanks.

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Try something like:

    create procedure Insert_Table1 (v_Unique ..., v_Description ...)
    ...

    if exists (select * from Table1 where _Unique = v_Unique)
    THEN SIGNAL SQLSTATE '75001' SET MESSAGE_TEXT = 'Value exists'
    else
    insert into TAble1 (_UNique, _Description) values (v_Unique, v__Description );
    END IF;

    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •