Problem With MS SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sibusiso
    New Member
    • Aug 2008
    • 18

    Problem With MS SQL

    HI

    Can Any one help I am having a problem with SQL triggers.

    I am having this table

    create table TTest(
    id bigint identity(100000 01,1),
    UID varchar(10),
    Fdesplayname varchar(50),
    primary key(id,UID)
    );

    On my triger I want to say
    FOR INSERT let the trigger take id and 'UID' and put it in field UID out put will look like 'UID1000001'

    the triger I did look like

    CREATE TRIGGER tr_Test
    ON dbo.TTest
    FOR INSERT
    AS
    BEGIN
    SET NOCOUNT ON;
    DECLARE @Num bigint
    SET @Num = (SELECT id FROM inserted);
    UPDATE TTest
    SET UID = 'UID'+@Num
    WHERE id = (SELECT id FROM inserted);
    END

    but it will only work if UID is no primary key

    Can Any one help

    Thanks
Working...