Return to Snippet

Revision: 40886
at February 9, 2011 14:12 by emregulcan


Updated Code
CREATE TRIGGER dbo.InsertTriggerOnGUIDYourtable
ON dbo.YourTable
FOR INSERT
AS
BEGIN
     SET NOCOUNT ON
	
     SELECT GUIDCol AS '@@GUID'
     FROM inserted
END

Revision: 40885
at February 9, 2011 14:09 by emregulcan


Initial Code
CREATE TRIGGER dbo.InsertTriggerOnGUIDTable2
ON dbo.GUIDTable2
FOR INSERT
AS
BEGIN
	SET NOCOUNT ON
	
	SELECT GUIDCol AS '@@GUID'
	FROM inserted
END
GO

Initial URL

                                

Initial Description
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 ;)

Initial Title
SQL Inserted Trigger

Initial Tags
sql

Initial Language
SQL