Link to home
Start Free TrialLog in
Avatar of cbeverly
cbeverly

asked on

SQL datbase export

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!
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

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

ASKER CERTIFIED SOLUTION
Avatar of Rich Weissler
Rich Weissler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.