I want to load a text file in a table and then remove the text file from the directory. How can I do that in SQL Server?
You use xp_cmdshell and BCP to do this. The basics are as follows:
exec master..xp_cmdshell 'bcp pubs..authors in c:filesauthors.txt /c /T' exec master..xp_cmdshell 'del c:filesauthors.txt'
For More Information
- What do you think about this answer? E-mail us at editor@searchDatabase.com with your feedback.
- The Best Microsoft SQL Server Web Links: tips, tutorials, scripts, and more.
- The Best SQL Web Links
- Have a SQL Server tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical SQL Server questions--or help out your peers by answering them--in our live discussion forums.
- Ask the Experts yourself: Our SQL Server guru is waiting to answer your toughest questions.
Dig Deeper on Microsoft SQL Server Installation
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.