4

I am trying to generate a data only script for a view using SSMS Generate Scripts feature. However, even though I select Data Only, it still only generates the view definition and not the data generated by the view. Is there something else I need to do?

I'm using SSMS for SQL Server 2014.

Randy Minder
  • 47,200
  • 49
  • 204
  • 358
  • Well, after digging for a while, I found a thread that might be helpful. Unfortunately, I don't know what your settings look like for the insert. Go down a couple of answers on this thread and take a look at the settings and see if yours match. http://stackoverflow.com/questions/982568/what-is-the-best-way-to-auto-generate-insert-statements-for-a-sql-server-table – SQL Taylor Mar 17 '15 at 17:26
  • Thanks but the thread you reference is almost 6 years old and a lot has changed with SSMS since then. The settings screen has changed quite a bit. – Randy Minder Mar 17 '15 at 17:35
  • Yep, that's all I could find. It doesn't look like a lot of people are having this issue based on the lack of people asking the question. A pretty intensive internet search yielded nothing for me and mine is working fine. You could always use another method. There are a couple of stored procedure scripts in that other thread I linked that will accomplish what you're trying to do. Sorry I couldn't be of more help. – SQL Taylor Mar 17 '15 at 18:23

3 Answers3

2

I know this is old, but I will answer it for other people who stumble on it.

Generate Scripts -> Data Only is bugged for views.

The easiest option without searching for other stored procedures or external tools is to copy the view contents into a table. Generate Scripts -> Data Only works fine with tables.

For example,

SELECT * 
INTO NEWTABLE
FROM dbo.Component

Then you can do Generate Scripts on the NEWTABLE and select Data Only in Advanced and it will work.

You can then delete the NEWTABLE.

erebel55
  • 600
  • 2
  • 8
  • 25
0

Given that Generate Scripts still doesn't appear to work for view data as of SSMS v17.9.1, an alternative depending on your needs might be to use the SQL Server Import and Export Wizard. You can read data from a view and write it to a table, across different databases and servers without resorting to a linked server.

enter image description here

enter image description here

Chris Peacock
  • 4,107
  • 3
  • 26
  • 24
-1

SSMS is still poor at this, VS has been able to do this for a while

Use menu VIEW->SQL SERVER OBJECT EXPLORER enter image description here

Create a new server Navigate down to your table or view , right click -> View Data

enter image description here

use the filter to limit the dataset to what you are interested in enter image description here

Then use the SCRIPT command (also available on context menu) enter image description here

This works for views and tables. Not super easy, but ill give it A-. Way better than other hacks that used to be available (including SSMS.ExportData which is not great)

hope that helps someone. I just had to export some rows and had to re-remember how to do this. hope it helps someone...

greg

greg
  • 1,673
  • 1
  • 17
  • 30