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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With