Reputation: 1461
I have a SQL Server 2008 database. This database has a table with 6 columns in it. I want to generate the insert scripts associated with the data only. I know how to do this part with SQL Server management studio via the "Advanced" dialog in the "Generate Scripts..." wizard. My challenge is, I only want to script 5 of the 6 columns. How do I do this?
Upvotes: 4
Views: 6916
Reputation: 21
SELECT Column1,Column2,Column3,Column4,Column5 INTO new table FROM your Existing table;
This will create a new table with the columns that you specified, then the data will be inserted in the new created table. Then script the new table that have only the five columns that you want.
Upvotes: 2
Reputation: 755461
Check out the FREE SSMS Tools Pack v2.0 - it has among a lot of other things a feature to generate INSERT
statements for data in your tables, and yes - you can pick for which columns that INSERT
statement should be:
Upvotes: 2
Reputation:
I don't think there's a way to do this. After you generate the full table script, you can do one of a few things.
If you want to preserve the actual field (keep it there), then just do something like:
update yourTable
set yourColumnThatYouDidntWantDataFor = null
Or, if you didn't want that field to be in the table at all, you can just drop it like so:
alter table yourTable
drop column yourColumnThatYouNoLongerWant
Upvotes: 0