Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate insert script for selected records?

I have a table with the following data:

Pk_Id  ProductName           Fk_CompanyId       Price ------------------------------------------------------ 1      AMX                   1                  10.00 2      ABC                   1                  11.00 3      APEX                  1                  12.00 4      AMX                   1                  10.00 5      ABC                   1                  11.00 6      APEX                  1                  12.00 7      AMX                   2                  10.00 8      ABC                   2                  11.00 9      APEX                  2                  12.00 

I want to generate Insert script for migrating records whose Fk_CompanyId is 1.

There is an insert script option to generate script for all records but I want to filter some records to migrate to another database.

like image 887
sudhAnsu63 Avatar asked Jul 19 '12 12:07

sudhAnsu63


People also ask

How will you generate insert script from select query in SQL Server?

Right click on the database > Tasks > Generate Scripts. Next. Select "Select specific database objects" and check the table you want scripted, Next. Click Advanced > in the list of options, scroll down to the bottom and look for the "Types of data to script" and change it to "Data Only" > OK.

How do I create a script insert?

Right-click on the database and go to Tasks > Generate Scripts. Select the tables (or objects) that you want to generate the script against. Go to Set scripting options tab and click on the Advanced button. In the General category, go to Type of data to script.


1 Answers

If you are using the SQL Management Studio, you can right click your DB name and select Tasks > Import/Export data and follow the wizard.
one of the steps is called "Specify Table Copy or Query" where there is an option to write a query to specify the data to transfer, so you can simply specify the following query:

select * from [Table] where Fk_CompanyId = 1 
like image 171
Tamir Avatar answered Oct 22 '22 14:10

Tamir