Version control: table modified date is changing but nothing seems to be modifying it! Why?

I have a series of databases. They're mirrors of each other in structure, only the data inside them changes. There's a database for each customer. Each night I run a procedure that checks if anything has changed in the database since the previous run and
e-mails me if it has. The reason for this was that an employee in the past was changing (and breaking) things so I wanted to track what was going on. Now, one of these databases is idle at the moment, in abeyance if you like, yet 1 table's modified date changes
once a week! Table definition stays stable at the level I am recording it (code below) so why is the modified date changing? Could it be an index-defrag? But if so, why this table and none of the others or indeed its mirror databases? CHECKDB run every day
and that's OK. Full backup done weekly. But again, why this 1 table? Nothing is even using the table at the moment! Code to get object definitions below.
SET
@command =
INSERT INTO TblSETUP_DatabaseVersionControl
SELECT
+ @database
+
''' as DatabaseName
+
CAST(@datestamp
as
varchar(20))
+
''' as SnapshotTime
,so.object_id as ObjectId
,so.[name] as ObjectName
,so.[type_desc] as ObjectType
,so.create_date as CreateDate
,so.modify_date as ModifiedDate
,CASE
WHEN so.type = ''U''
THEN tbl.TableDefinition
WHEN so.type = ''SN''
THEN ''CREATE SYNONYM ['' + ss.name + ''] FOR '' + ss.base_object_name
ELSE sm.definition
END as ObjectDefinition
FROM '
+ @database
+
'.sys.objects so
LEFT OUTER JOIN '
+ @database
+
'.sys.sql_modules sm
ON so.object_id = sm.object_id
LEFT OUTER JOIN (SELECT
td.object_id
,SUBSTRING(td.TableDefintionRaw,1,LEN(td.TableDefintionRaw)-1) + '')'' as TableDefinition
FROM (
select
so1.object_id
,(select
CASE
WHEN sc.column_id = 1
THEN ''CREATE TABLE ['' + so.name + ''] ([''
   + sc.name + ''] [''
   + st.name + '']''
+ CASE WHEN st.name LIKE ''%char%'' THEN ''('' + CAST(sc.max_length as varchar(5)) + '')'' ELSE '''' END
+ CASE WHEN sc.is_nullable = 1 THEN '' NULL,'' ELSE '' NOT NULL,'' END
ELSE ''['' + sc.name + ''] [''
+ st.name + '']''
+ CASE WHEN st.name LIKE ''%char%'' THEN ''('' + CAST(sc.max_length as varchar(5)) + '')'' ELSE '''' END
+ CASE WHEN sc.is_nullable = 1 THEN '' NULL,'' ELSE '' NOT NULL,'' END
END
from '
+ @database
+
'.sys.objects so
inner join '
+ @database
+
'.sys.columns sc
on so.object_id = sc.object_id
inner join '
+ @database
+
'.sys.types st
on sc.user_type_id = st.user_type_id
where so.type = ''U''
AND so.object_id = so1.object_id
order by sc.column_id
FOR XML PATH('''')) AS TableDefintionRaw
from '
+ @database
+
'.sys.objects so1
WHERE so1.type = ''U''
group by so1.object_id) as td) as tbl
ON so.object_id = tbl.object_id
LEFT OUTER JOIN '
+ @database
+
'.sys.synonyms ss
ON so.object_id = ss.object_id
WHERE so.[type] IN(''P''  -- Stored procedures
  ,''V''  -- Views
  ,''U''  -- User table
  ,''SN'' -- Synonym
  ,''FN'' -- Function
ORDER BY so.[type],so.name
JCEH

Incidentally, I remember the second reason I set all this up. I had a view that used to revert back to an old definition under SQL 2008. It was weird. More than 1 of us had gone in and "fixed it" and then it unfixed itself. It turned out the view had been
renamed in the past. Each night I have a procedure that checks all views in the instance running sp_refreshview. Any errors are caught and e-mailed to me. It seems that the old definition was still stored somehow under the old name but with the same object
id (there had been some corruption in the database when a drive in the RAID5 array became suspect  - picked up with CHECKDB, Windows and indeed the HP software didn't pick anything up). Although the database had been "fixed" this view switched back to
the old definition each time sp_refreshview was run. Fix was to drop and re-create using new definition. Learnt the lesson though and now keep track of all main definitions in each instance.
J
JCEH

Similar Messages

Maybe you are looking for