[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/pabloperalta] October 2008 - Posts - Pablo Peralta's Blog

October 2008 - Posts

It is common that for certain tables in our DBs we include the creation date and last modification date for every row.

This implies that we have to manually create a trigger for that.

I found the following script  that saves our time and avoid to write it manually.

Simply:

-          Create the columns in our table (here named ‘Created’ y  ‘LastModified’) respectively.

-          Find & replace ‘TableName’ and  ‘UniqueID’.

That is. Simple, clear :).

The script:

CREATE TRIGGER tr[TableName]CreateDate ON [TableName]

FOR INSERT

AS

UPDATE [TableName] SET [TableName].Created=getdate()

FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]

 

GO

 

CREATE TRIGGER tr[TableName]LastModifiedDate ON [TableName]

FOR UPDATE

AS

UPDATE [TableName] SET [TableName].LastModified=getdate()

FROM [TableName] INNER JOIN Inserted ON [TableName].[UniqueID]= Inserted.[UniqueID]

Well, it seems that some rumors are becoming true and some old development paradigms appear to be challenged. New ways of conceptualizing and developing software are becoming more and more near.

I am sharing here a news by Steve Ballmer about the new 'Cloud Windows' which could be out within a month!

http://www.computerworld.com/action/article.do?command=viewArticleBasic&articleId=9115978

More Posts