Question : sql 2005 incremental update

hi all,
i have to update data from transactional table to my staging table. i want the data to be update incrementally from ttable to staging table. i mean when any new records are inserted into ttable only those records has to be inserted into staging table. i run the schedule on everyday night.

how can i do that
my main primary key is product_id

Answer : sql 2005 incremental update

Check this topic:

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23465524.html#a21737015

What we did there was to create a trigger for table A that whenever records where inserted/deleted/updated on it, the change would automatically reflect on table B.

You can implement only the INSERT part, if the update and delete don't apply to your needs.

Now, if you want something that will work based on a daily schedule, do this:

On the table that holds the initial records, add a column that holds the insertion date, like this:

ALTER TABLE YourTable ADD COLUMN InsertDate datetime not null default GetDate(),


Then create a stored procedure or DTS package that will look for records inserted on a specified date and insert them on the other table:

INSERT INTO TheOtherTable (Field1, Field2, Field3, Fieldn)
   SELECT Field1, Field2, Field3, Fieldn
   FROM YourTable
   WHERE CONVERT(DATETIME, CONVERT(INT, GETDATE()-1)) = CONVERT(DATETIME, CONVERT(INT, InsertDate))


This will Insert into TheOtherTable all the records that were inserted into YourTable on the previous day. I am assuming you will be running the procedure right after midnight.

Random Solutions  
 
programming4us programming4us