Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Location
    Pakistan, Karachi
    Posts
    22

    Question Unanswered: Insert Trigger How to work

    Hi All!

    I have a table which has fields |person_id| AND |fullname|

    I would like to create and insert trigger so that no duplicate names shoudl be inserted, I tryed Following but am geeting confused Where I am going Wrong

    I need to take an Input from user to this trigger as well how is it possiible??

    create trigger ins_per
    on persons
    for insert as
    Declare @p_name varchar(45)
    select * from persons where full_name=@p_name
    if @@rowcount>0
    Begin
    Print
    'Sorry'
    ROLLBACK TRANSACTION
    End

  2. #2
    Join Date
    Feb 2002
    Location
    Sweden
    Posts
    34
    A unique constraint does the trick!

    Alter table x add constraint constraint_name unique nonclustered (Column 1,Column 2)

    The combination column1 + column2 must be unique.

    Hope it helps!
    - Jonte

Posting Permissions

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