Export contents of SQL Server 2008 R2 table to CSV WITHOUT xp_cmdshell

情到浓时终转凉″ 提交于 2019-12-13 07:21:23

问题


I need to export the contents of a SQL SErver 2008 R2 Express table to a CSV or TXT file.

I cannot enable xp_cmdshell nor can I allow ad hoc distributed queries.

It needs to be executable from a trigger on one of the tables.


回答1:


USE master;  
GO  
EXEC sp_configure 'show advanced option', '1';  
RECONFIGURE;  
EXEC sp_configure; 
EXEC sp_configure 'Ad Hoc Distributed Queries', '1';  
RECONFIGURE;  
EXEC sp_configure; 

INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
                       'Text;Database=C:\Temp\;HDR=Yes;',
                       'SELECT * FROM test.csv')
            (object_id, name)

SELECT 'object_id', 'name'

UNION ALL

SELECT object_id, name
FROM sys.tables

--This require csv file to be there at location

Follow this Link , if you face any problem while insertion.

Once working you use same script in trigger.



来源:https://stackoverflow.com/questions/40028326/export-contents-of-sql-server-2008-r2-table-to-csv-without-xp-cmdshell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!