欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Simple way to export SQL Server data to Text

系統(tǒng) 1918 0

Simple way to export SQL Server data to Text Files

?

























Simple way to export SQL Server data to Text Files
??? By: Ken Simmons?? |?? Read Comments (7)?? |?? Related Tips: More
Win an eBook - select from over 1,000 titles!

Problem
Since the transition from DTS to SSIS, I have found myself looking for alternative ways to do simple tasks such as exporting data from SQL Server into text files. SSIS is a far more powerful tool than DTS, but I generally try to stay away from it for simple operations.? With the combination of a few T-SQL commands this tip shows you a simple way to export data to text files.

Solution
One of the ways I have worked around this is by using bcp with xp_cmdshell. It's fast, easy and I can integrate it right into my code.

The first thing you have to do is make sure xp_cmdshell is enabled. You can do this in one of two ways.

1. You can use sp_configure and execute the following script.
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE

2. You can use the Surface Area Configuration Tool.

Select Surface Area Configuration for Features and check the Enable xp_cmdshell checkbox.

Now that you have xp_cmdshell enabled you are ready to export your files.

Here is a sample command that will export the results of the sysfiles table to a comma delimited file called bcptest.txt. Just copy and paste this into a query window and execute the query.
EXEC xp_cmdshell 'bcp "SELECT * FROM sysfiles" queryout "C:\bcptest.txt" -T -c -t,'

Note: BCP is a command line utility and xp_cmdshell is only required to use it within a SQL Batch.

This is the output for the above command when run in the "master" database.

The parameters that were used are:

??? The queryout option allows you to specify a query to export. This could be as simple as the query we have are as complicated as you want.? You can also create a view and select the data from a view.
??? The file name where the results will be stored is placed after the queryout option.
??? The -T parameter specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security. You could use -P (password) and -U (user) if you want to use a SQL Server login.
??? The -c specifies the character dataype will be used for each field.
??? The -t parameter allows you to specify a field delimiter. The character after -t will be used to separate the data fields. If -t is removed, tab will be used as the default delimiter.

Another parameter you may need to use is -S to specify the server name.? If you have a named instance, you will need to use this parameter.? Here is an example connecting to server "DEVELOP" and instance "DEV1".
EXEC xp_cmdshell 'bcp "select name, type_desc, create_date from sys.objects" queryout "C:\bcptest2.txt" -T -SDEVELOP\DEV1 -c -t,'

Also be aware that the case of the parameter such as -t and-T makes a difference, so make sure you have correct case for the parameter you are using.? You can find more options for BCP here:? http://msdn.microsoft.com/en-us/library/ms162802.aspx

Next Steps

SQL Server DBA Tips SQL Server Developer Tips SQL Server Business Intelligence Tips SQL Server Tip Categories SQL Server Career Tips SQL Server Jobs SQL Server Tutorials SQL Server Webcasts SQL Server Whitepapers SQL Server Tools SQL Server Questions and Answers MSSQLTips Authors About MSSQLTips SQL Server User Groups SQL Server Events MSSLQTips Giveaways MSSQLTips Advertising Options

Simple way to export SQL Server data to Text Files


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 日本黄色大片免费看 | 午夜精品久久久久久91 | 97国产精品视频人人做人人爱 | 91福利免费观看 | а√天堂资源中文最新版地址 | 欧美视频99 | 精品人成| 国产乱码视频 | 91精品国产闺蜜国产在线 | 国产日韩欧美视频在线观看 | 久久亚洲第一 | 色综合色综合网色综合 | 91精品国产综合久久久久久 | 亚洲日本在线天堂无码 | 日韩六九视频 | aⅴ免费在线观看 | www.色.com | 国产色| 国产精品美女www爽爽爽视频 | 色婷婷综合久久久中文字幕 | 啪一啪在线视频 | 色欲AV色情国产又爽又色 | 久视频免费精品6 | 天天躁日日躁狠狠躁中文字幕 | 日本免费观看官网 | 国产伦理久久精品久久久久 | 超碰一区 | 91久久久久久 | 欧美国产伦久久久久 | 国产青青 | 国产综合在线播放 | 精品的一区二区三区 | 国产精品成人av | 人人爽人人爽 | 亚洲一二三四2021不卡 | 国产成人在线一区二区 | 水中色av综合 | 久久亚洲综合 | 亚洲AV在线无码播放毛片浪潮 | 五月婷婷六月丁香 | 亚洲一区二区三区91 |