Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger Help 1

Status
Not open for further replies.
Dec 31, 2004
71
GB
Hi All,
I am having an issue at the moment where I need to generate a random guid (uniqueidentifier) within a table when a row is inserted.

I am after some clarity that the quickest way to atchive this would be to drop the column and re-add it using;

CREATE TABLE MyUniqueTable
(UniqueColumn UNIQUEIDENTIFIER DEFAULT NEWID(),
Characters VARCHAR(10) )
GO

would the insert statment need to use newid() ?

Is there a way I can implement a trigger after insert to generate this value (if it has not already been generated)?

Thanks
Nathan
 
Why would you not open the table in design mode and set that particular columns DEFAULT to be NEWID(). That way when the record is inserted, the new GUID is created and populates the field?

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top