Posted By

emregulcan on 02/09/11


Tagged

sql trigger guid newId uniqueidentifier


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

emregulcan


SQL Inserted Trigger


 / Published in: SQL
 

This trigger returns a resultset that includes last inserted record's guid info (uniqueidentifier)

If your column is uniqueidentifier and its default value is newid() , you can't get last record id (guid) with @@identity .

So, I write a trigger on my table to get last record guid info ;)

  1. CREATE TRIGGER dbo.InsertTriggerOnGUIDYourtable
  2. ON dbo.YourTable
  3. FOR INSERT
  4. AS
  5. BEGIN
  6. SET NOCOUNT ON
  7.  
  8. SELECT GUIDCol AS '@@GUID'
  9. FROM inserted
  10. END

Report this snippet  

You need to login to post a comment.