Database bcp Import Export batch processing tool

Source: Internet
Author: User

Should the company planning requirements, need a database to import and export the tool with SVN to make the difference matching, easy to plan the database modification of the record tool, I use the bcp command to implement the following batch processing tools, in the middle of a lot of pits, is saved here hope to help the students need this tool.

:: Database Address set ip=127.0.0.1:: Database Account set LOGIN=SA:: Database Password set Passward=passward:: Database name set Database=mydbname:: The path set to save TXT file Filepath=d:\data:: Import into the database (this way comment off the above in is exported from the database to TXT, comment out the following is imported from TXT to the database):: Set Way=in:: Export to txt text set Way=out:: This way, first create a folder, according to personal needs MD%filepath%:: This way fill in the database table name set Datatable=table1 table2 table3 table4 table5 table6:: This is done on an import or export basis to delete a database table, because BCP imports to the database if the original database has data will appear duplicate key does not let insert error causes insert failure if%way% = = in (for%%i in (%datatable%) does osql-s%ip %-u%login%-p%passward%-Q "TRUNCATE TABLE%database%. %%i "):: Here is a table data import and export operation, using the bcp command for%%i in (%datatable%) do bcp%database%: %%i%way%%filepath%%%i.txt-c-S%ip%-u%login%-p%passward%pause

Copy the code into a TXT file, modify the appropriate parameters, save the file in the bat format to use, SQL Server sqlserver2012 test can be used

The bcp command needs to install the Sqlmanagementstudio tool, which is no longer described in the tool and can be found on the web.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.