简体   繁体   中英

How can I export the record sets of the view to sql with using SQL Server Management Studio Express?

I'm trying to make an automation to export the record sets of the view.
Currently, it's possible to do it if I do them all manually like below. I'm using SQL Server Management Studio Express and it's connected to the server via ODBC.

  1. Click on New Query
  2. Open Query Designer and add a view(Consider the view name is Movies)
  3. Input " select * from Movies; "
  4. Press Execute and wait until it finishes retrieving all the record.
  5. Right Click on the record sets of the result and select Save results as
  6. Export the records as csv

In fact, I'd like to export it as sql instead. Is it possible? and how can I make this process automated?

Can anyone help on this?

If you can use BCP commands, please test following export SQL data to local file script

DECLARE @cmd varchar(1000)
SET @cmd = 'bcp "SELECT * FROM Kodyaz.dbo.tablename" queryout "C:\textfile.csv" -t; -c -UTF8 -T -Slocalhost'
EXEC master..xp_cmdshell @cmd

In the FROM clause, place the fully qualified name of the database table with dbname, schema and table name You have the option to set the target file too

You can experience error before running the script successfully For example, you may need to enable xp_cmdshell and grant write permission to SQL Server service user on the file folder

I hope that helps as an alternative to SQL Server Import Export Wizard,

请检查SQL Server导入导出向导(如果您的SSMS上可用),如果可以使用它,请按照将SQL Server导出到Excel中所述的步骤进行操作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM