Solved

SQL datbase export

Posted on 2013-07-01
3
340 Views
Last Modified: 2016-02-11
I am trying to export a SQL database which I generally do in SQL Server Management Studio (2008) using Generate Scripts. This works fine for exporting the entire database and data, however, I'd like to just export only select fields. I tried creating a view and exporting only the view but I never saw any of the data (even after selecting  "Schema and Data" in types of data to script under Advanced.
Is there a way to export data and schema using a Select query for only certain fields and data you'd like exported?
Thanks!
0
Comment
Question by:cbeverly
  • 2
3 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 39291257
Well... there's always a way.  Whether or not its a *nice* way is debatable.  There's no direct way of doing what you want.

My suggestion - create a new table containing the data structure you want and export that (then delete it):

SELECT f1
  , f2
  , f3
INTO new_table_to_export
FROM original_table
WHERE condition if you need it

// export your table ....

DROP TABLE new_table_to export

Open in new window

0
 
LVL 30

Accepted Solution

by:
Rich Weissler earned 500 total points
ID: 39291288
If you already created a view, and wanted to export the data from a view, could you not use the SQL Server Import and Export Wizard, and in the 'Select Source Tables and Views' -> select the view you wanted to export that data through?

It all just uses SSIS, so ultimately you could do even more customization by firing up your Visual Studio with BITS.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39291324
Another option would be to use 'bcp' with a query.  That'll export a table out as well, and you can specify how you want it formatted:

http://msdn.microsoft.com/en-us/library/ms191485.aspx

Not sure what you're then trying to import this into.  If its another SQL server, you can use BCP's internal binary format.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question