简体   繁体   中英

How can I know what changed in a SQL database for a certain time?

I have a system to manage printers of a company and I need to understand how the workflow between the Website and database works by knowing what is added/changed in the database with each interaction of the user. Is there a way to find or create some kind of log for a database or even the entire SQL Server that can show me what I need?

I think what you're looking for are triggers. You can make tables to log the currently updated or changed data and use triggers to automatically feed data in the log table on any change

CREATE OR REPLACE TRIGGER [trigger_name]
BEFORE DELETE OR INSERT OR UPDATE ON [table_name] 
  FOR EACH ROW 
  WHEN [some condition] 
  DECLARE 
  [variable declaration]
  BEGIN 
     [create an entry in the log table here]
  END; 

You can use NEW and OLD keywords to refer to the data (new referring to the most recent update of data)

Just for the record, a tool for that exactly purpose exists and is installed together with SQL Server, it is called SQL Server Profiler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM