December 28, 2005 at 8:24 am
Dear All,
I have a database which is having more than 100 tables and all the tables are almost updated daily from my application which is on VB. My database is in SQL 2000.
Now what i want is i have to download the incremental data in the text file. Incremental data means i need all the rows created / modified today.
I have one option by which i can create common field and common trigger in each table by which i will update the field whenever rows are inserted/updated in that table. But it seems very cumbersome to create a field and trigger in each table.
Any help in this matter is highly appreciated.
Thanks in Advance.
Shakti
December 28, 2005 at 8:50 am
I can't see a better way around the need to have a field per table.
If your database design allows there to be a "common properties" table then your UpdatedDate field could go in that table but that still doesn't get around the fact that every single add/update routine needs to update the table.
I would not use a trigger to update the tables because the triggers can be very CPU intensive. I don't know why, they just are.
I would set the UpdatedDate field to have a default of GETDATE() so you only have to worry about the UPDATEs.
December 28, 2005 at 9:36 am
You could see if Red Gate's Data Compare or the ApexSQL tool could give you a flat file of data, but it would be by tables.
I like David's advice if you are going to roll your own.
December 28, 2005 at 10:00 pm
i agreed by the suggestion given by David. I also have thought about that. But what about Updates. i also need rows that have been updated.
December 29, 2005 at 3:59 am
I would still use a trigger: I am using a Audit trigger on all my tables which is generic (see below): Therefor its easy to deploy.
All the Trigger does calles the SYSTEM_Audit Procedure with the Process ID and some other information. System_Audit in turn is the central place where the UPDATED_COLUMNS() is checked and logs are writen depending if the column in question is listed in the table SYS_Objects which has a flag AuditChanges.
I have added another level of abstraction, where SYSTEM_Audit_RegisterObject Procedure is called (not listed here) which checks if the column in question is existing in the tbl_SYS_Objects. If not it inserts it and returns an Audit = 0 , if yes it returns the AuditChange Field (bit field)
Depending on that a log is written or not.
Does that help?
--- Sample Audit Trigger---
CREATETRIGGER _Audit ON
December 29, 2005 at 10:37 am
Why build on David's suggestion not devote 2 columns instead of 1. The first column is a creation date/tim, the second column is a modification date/time. (it's something we did 2+ decades ago in the mainframe world ... back then we also added creating user and modifying user too !)
RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply