Click here to Skip to main content
15,917,538 members
Home / Discussions / Database
   

Database

 
Generalbetter way for moving data from one to three table Pin
mohd imran abdul aziz19-Feb-08 21:45
mohd imran abdul aziz19-Feb-08 21:45 
GeneralAutoincrement character type data in sql server Pin
techie.priyanka19-Feb-08 20:17
techie.priyanka19-Feb-08 20:17 
GeneralRe: Autoincrement character type data in sql server Pin
Hesham Amin19-Feb-08 20:53
Hesham Amin19-Feb-08 20:53 
GeneralRe: Autoincrement character type data in sql server Pin
techie.priyanka21-Feb-08 22:18
techie.priyanka21-Feb-08 22:18 
GeneralRe: Autoincrement character type data in sql server Pin
Hesham Amin21-Feb-08 22:29
Hesham Amin21-Feb-08 22:29 
Generalhelp in inserting into a table Pin
mrcsn19-Feb-08 20:12
mrcsn19-Feb-08 20:12 
GeneralRe: help in inserting into a table Pin
Krish - KP19-Feb-08 20:16
Krish - KP19-Feb-08 20:16 
GeneralRe: help in inserting into a table Pin
mrcsn19-Feb-08 21:24
mrcsn19-Feb-08 21:24 
GeneralAutomatic email sending function Pin
Jamman19-Feb-08 19:50
Jamman19-Feb-08 19:50 
GeneralRe: Automatic email sending function Pin
Steven J Jowett20-Feb-08 4:52
Steven J Jowett20-Feb-08 4:52 
Generalsql inserting Pin
mrcsn19-Feb-08 18:12
mrcsn19-Feb-08 18:12 
GeneralRe: sql inserting Pin
Krish - KP19-Feb-08 20:12
Krish - KP19-Feb-08 20:12 
GeneralCopy data In table [modified] Pin
kibromg19-Feb-08 6:08
kibromg19-Feb-08 6:08 
GeneralRe: Copy data In table Pin
Mark J. Miller19-Feb-08 7:50
Mark J. Miller19-Feb-08 7:50 
GeneralRe: Copy data In table Pin
kibromg19-Feb-08 9:19
kibromg19-Feb-08 9:19 
GeneralRe: Copy data In table Pin
Mark J. Miller19-Feb-08 11:16
Mark J. Miller19-Feb-08 11:16 
Does the data in the production table change at all (UPDATE/DELETE)? Or is it always new data (INSERT)?

One answer is to use Red Gate's SQL Data Compare. It's pretty cheap and you can write a script to sync the tables every two hours.

You could dump/refresh the backup table.

Method 1:
This would work much like using the Red Gate tool.

1) Add a timestamp column to the livedata table and a binary column to the backupdata table
2) Compare and update existing data (UPDATE b SET column = live.column FROM backupdata b INNER JOIN livedata live ON live.ID = B.ID WHERE live.stamp <> b.stampcopy)
3) Insert all data from livedata that doesn't exist in backupdata

Method 2:

1) Create a logging table that records which records in livedata have changed and the change that was made (INSERT, UPDATE, DELETE).

2) Create a trigger on livedata would add a record to the logging table including ID, Action, ActionTime. (ActionTime could be a timestamp or datetime).

3) Write a script that reads the log table, and syncs the backupdata table on a schedule based on the ID and the action with the oldest ActionTime.

Method 3:

TRUNCATE TABLE backupdata<br />
INSERT INTO backupdata (columns)<br />
SELECT columns FROM livedata


Method 4:

CREATE TABLE backupdata_temp (<br />
 columns.....<br />
)<br />
<br />
INSERT INTO backupdata_temp (columns)<br />
SELECT columns FROM livedata<br />
<br />
DROP TABLE backupdata<br />
<br />
EXEC sp_rename ......


Either way make sure you wrap the whole thing in a transaction and set the logging mode to BULK LOGGED before you do it and then change the logging mode back when you're done. Also, if you use method 3, make sure you recreate any indexes you had that were on the backup table.

The choice of methods will depend on the availability requirements for the backup table and the amount of data you're working with.


GeneralRe: Copy data In table Pin
kibromg19-Feb-08 23:21
kibromg19-Feb-08 23:21 
GeneralRe: Copy data In table Pin
kibromg19-Feb-08 23:48
kibromg19-Feb-08 23:48 
GeneralRe: Copy data In table Pin
Mark J. Miller20-Feb-08 6:54
Mark J. Miller20-Feb-08 6:54 
GeneralAPPLICATION TO RUN EVERY FEW SECONDS Pin
kibromg21-Feb-08 5:27
kibromg21-Feb-08 5:27 
QuestionAdvice sought, how do I best handle saving an array in a SQL database? Pin
Per Sderberg19-Feb-08 5:06
Per Sderberg19-Feb-08 5:06 
GeneralRe: Advice sought, how do I best handle saving an array in a SQL database? Pin
Mark J. Miller19-Feb-08 8:26
Mark J. Miller19-Feb-08 8:26 
GeneralRe: Advice sought, how do I best handle saving an array in a SQL database? Pin
Per Sderberg19-Feb-08 21:41
Per Sderberg19-Feb-08 21:41 
QuestionHow do I merge data into one record Pin
KreativeKai19-Feb-08 4:16
professionalKreativeKai19-Feb-08 4:16 
GeneralRe: How do I merge data into one record Pin
Mark J. Miller19-Feb-08 8:12
Mark J. Miller19-Feb-08 8:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.