Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Apr 3, 2003

Synchronizing Production Data with a Test Database on SQL Server - Page 2

By DatabaseJournal.com Staff

by MAK [Muthusamy Anantha Kumar]

Step 3: Automate the restore process

Create a job for restoring the database backup in the test server with the following job steps.

Kill Users

Add this SQL statement as the first job step, which kills all the users on the database.

EXEC USP_KILLPROCESS " MyDatabaseName"

Restore database

Add this SQL statement as the second job step to restore the database from the fileserver. Remember to change the database name, data and log location.

Restore database MyDatabaseName from disk = 
\\Fileserver\Sharedfolder\Product.Bak with replace,
Move "Product_Data" to "d:\mssql\data\Product_data.mdf",
Move "Product_Data" to "d:\mssql\log\Product_log.ldf"

Encrypt Sensitive data

Add these SQL statements as the third step, which encrypts sensitive data such as SSN, Credit card numbers etc.

Use Mydatabasename
Go
Update accounts set revenue = master.dbo.encryp(revenue, char(rand()*100))
Go
Update personal set crcardnum = master.dbo.encryp(crcardnum, char(rand()*100))
Go
Update accounts set SSN = master.dbo.encryp(SSN, char(rand()*100))
Go

Synchronize sysusers

In practice, production and test servers will have the same logins and users but the passwords will be different. When the production database backup has been restored in the test server, the sid column in the sysusers table will not be in sync with master table login. In order to bring it back into sync, add the script below as the fourth step.

use master
go
sp_configure "allow updates",1
go
reconfigure with override
go
use MyDatabaseName
go
update sysusers set sid = 
(select sid from master.dbo.syslogins where name = 'UserId1') where name = 'UserId1'
go
update sysusers set sid = 
(select sid from master.dbo.syslogins where name = 'UserId2') where name = 'UserId2'
go
sp_configure "allow updates",0
go
reconfigure with override
go

Step 4: Schedule the job

This job can either be scheduled daily at night or can be run on demand.

Conclusion:

By providing an automated production-test data sync process, the QA group does not have to depend on the DBA for restoring the production data; they could run this job whenever they needed. You can use the same process for all the databases that you would like to synchronize with production data.



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM