views:

51

answers:

5

Hi,

I want to select the records from a table which are updated or added in the last one month (table doesn’t have any datetime field and I can’t change the table structure). Is it possible to write a sql query for that? how to fetch those records from table.

regards, kumar

A: 

No It is not possible. You need to keep a track of that by adding the date fields to the structure of the table. we cannot do as you said.

Vijay Sarathi
+1  A: 

It is possible if you are allowed to use triggers and add extra tracking tables(whilst leaving the existing table structure untouched)

Obviously you would not be able to find out what has already changed but this would enable you to come up with a solution to track changes made once implemented.

If this is useful then let me know and I can give you more details.

David Steele
thanx for u r suggestion. but we not using any kinds triggers Is there any other scenarios that we can do it ?
kumar
In that case it isn't possible to do what you want to do, you can't magic data out of thin air. If you were in SQL 2008 you may be able to enable change tracking but that is the last shred of hope for this.
David Steele
I can't magic the data out in air. but i will try .In that case is it possible to use getDate() or sys.objetcs or @@IDENTITY to get the records from table which r updated in last one month can i use any them or all?
kumar
+1  A: 

If you are using SQL Server 2008 (or have the ability to upgrade), you could have a look at using Change Data Capture to track when changes are made to your tables. This solution would not involve changing existing tables, but you would be making a database-level change.

If upgrading to 2008 is not an option, you can create a set of change tracking tables and use triggers to maintain them when updates are made.

Terrapin
A: 

If you can't ;

  1. Modify the db to add a timestamp col.
  2. Add another table that acts as an audit log, fed from a trigger on the original table

Then you'll need to write an ssis package that, at the end of every day compares the table in question to a copy of the table (that you took the previous day). You then log any differences in a new audit table.

GordonB
A: 

It's not possible by querying that table.

You can get that records by verifying the transaction logs in Oracle. But i am not sure in Sql Serevr.

Dinesh