Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Scripts for Specific Records in SQL Server

This is probably a bit of a limited, but valuable scenario. I have a SQL Server 2008 database with a table that has millions of records. There appears to be an intermittent problem with several of the records. I'm trying to repro the problem. In an effort to do this, I finally got the ID of an offending record. I would like to generate an INSERT statement associated with this single record in my PROD database. Then I can easily migrate it into my TESTING database in an effort to repro and resolve the problem.

Basically, I need to generate a single INSERT statement for a single record from a single table where I know the primary key value of the record.

Does anyone have any ideas of how I can accomplish this? Essentially, I want to generate insert statements on a conditional basis.

Thank you!

like image 356
user70192 Avatar asked May 17 '12 12:05

user70192


1 Answers

First try to recreate what you want to insert with a SELECT statement.

After that you can insert into the table with a INSERT INTO like this:

INSERT INTO tablename
SELECT ....

If they are on different servers, you can use INSERT like this:

INSERT INTO tablename VALUES (...)

using the values given by the SELECT in the other server fill the values in the insert.

like image 78
aF. Avatar answered Sep 20 '22 01:09

aF.