Check for changes to an SQL Server table?

前端 未结 8 1085
有刺的猬
有刺的猬 2020-12-04 08:02

How can I monitor an SQL Server database for changes to a table without using triggers or modifying the structure of the database in any way? My preferred programming enviro

8条回答
  •  自闭症患者
    2020-12-04 08:33

    Have a DTS job (or a job that is started by a windows service) that runs at a given interval. Each time it is run, it gets information about the given table by using the system INFORMATION_SCHEMA tables, and records this data in the data repository. Compare the data returned regarding the structure of the table with the data returned the previous time. If it is different, then you know that the structure has changed.

    Example query to return information regarding all of the columns in table ABC (ideally listing out just the columns from the INFORMATION_SCHEMA table that you want, instead of using *select ** like I do here):

    select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'ABC'
    

    You would monitor different columns and INFORMATION_SCHEMA views depending on how exactly you define "changes to a table".

提交回复
热议问题