0

For example, I have UserId column which is identity column of my table. When I add new data to table, UserId assign 1 automatically. If enter new data, the number in the column increases one by one.

UserId - UserName - UserLastName
1        asd        asd
2        xyz        xyz

I want to change UserId's starting value and increase it by my condition.

UserId - UserName - UserLastName
US1        asd        asd
US2        xyz        xyz

Is it possible to increase string values like above ?

1 Answers1

0

If you are using Oracle database, you can create a trigger for that.

 Create or Replace TRIGGER "SYSTEM".Trigger_Name 
    BEFORE INSERT ON Table_Name 
    FOR EACH ROW 
    BEGIN
      <<COLUMN_SEQUENCES>>
      BEGIN
        IF INSERTING AND :NEW.UserID IS NULL THEN
          SELECT 'US'||to_char(Sequence_Name.NEXTVAL,'FM00') INTO :NEW.UserID FROM SYS.DUAL;
        END IF;
      END COLUMN_SEQUENCES;
    END;
Jinesh Shah
  • 922
  • 10
  • 18