The timestamp is a binary number used to determine whether or not someone has changed the data between the time you fetched the record and the time you updated the record. Its purpose is to prevent us from over writing someone else’s changes.
The following script can be used to add the TIME STAMP column to one table at a time.
ALTER TABLE yourtablename ADD TIMESTAMP
The below script will add the TIMESTAMP column to all tables in your database. WARNING! THIS WILL ALTER ALL YOUR TABLES! This script assumes you do not already have any TIMESTAMP columns in your tables.
DECLARE @TableName TABLE ( query VARCHAR(1000) )
INSERT INTO @TableName
SELECT 'Alter table ' + Name + ' ADD TimeStamp'
FROM sys.objects
WHERE Name <> 'dtProperties'
AND type = 'u'
--The below line is used to look at the data prior to executing it.
SELECT *
FROM @TableName
--WARNING - this script will ADD the TIMESTAMP COLUMNS TO ALL your tables!
--Comment out the RETURN line to auto run this script.
RETURN
DECLARE @sql VARCHAR(1000)
SET @sql = ''
WHILE EXISTS ( SELECT *
FROM @TableName
WHERE @TableName.query > @sql )
BEGIN
SELECT @sql = MIN(@TableName.query)
FROM @TableName
WHERE @TableName.query > @sql
EXEC(@sql)
END