tags:

views:

205

answers:

6

Often I find myself working on a new project with a giant RDBMS whose schema I don't yet understand. I want to be able to mark a checkpoint in the database, do something in the app, and then go back to the database and ask it which tables changed (and ideally, what records changed).

Is there a way to do something like this with SQL? I found this, but it's MSSQL-only (which I'm not using).

It doesn't need to be super efficient. It's just going to be on my dev box and I can wait a few seconds if need be, but I am looking for something better than "dump the whole DB twice and diff the results".

+2  A: 

If your DBMS supports query logging, turn it on and tail -f the log.

chaos
That's probably simplest. I don't know why I didn't think of it.
Ken
+2  A: 

SQL Server and Oracle both have a feature you can enable called "Change Data Capture". You said you're not using SQL Server, but there's still hope here if you're on Oracle. Perhaps you should mention what dbms you use.

Joel Coehoorn
SQL Change Data capture only works in the enterprise edition. Got ca$h ?
CAD bloke
Sometimes MySQL, sometimes Postgres, sometimes SQLite ... I was hoping (ha!) for a method that would work on any SQL DB.
Ken
A: 

I'm pretty I once came across a MySQL proxy tool that sat between you and the server.

I doubt you'll come across one solution that will work on every SQL DB. (Dump all the table to .SQL or .CSV files before and after and diff them?)

Eli
A: 
  • Add triggers to all tables that log all changes.
  • Check if you can hook into the data access layer of your application to log things
  • or if it supports logging out of the box. (I think ODBC on Windows supports this.)
svinto
A: 

Your best bet would be to see if your RDBMS offers a proprietary feature that would do this, or add update triggers that would log events.

A: 

In mysql, I use a column

modified timestamp

to retrieve the rows that changed

Pierre