Restore the qualified files of Location A to the machine of location B. The Administrator of the other party does not understand anything, so he wants to be a dumb as much as possible, so as not to explain to him how to perform the operation for half a day.
-- Export a text file using a query statement
-- Exec master .. xp_cmdshell 'bcp "select * from [TestDB11-27] .. restoreweihai "queryout c: \ test.txt-F 2-C-s" 192.168.102.122 "-U" sa "-P" pass "'
-- Export the query data to an XML file
-- Exec master .. xp_cmdshell 'bcp "select * from [TestDB11-27] .. tline_tw for XML raw, binary
Base64 "queryout c: \ AA. XML-C-s" 192.168.102.122 "-U" sa "-P" pass "'
-- Import data from text files to databases
-- Exec master .. xp_mongoshell 'bcp customer .. order in C: \ test.txt-C-s "192.168.102.122"-U sa
-P pass'
Note the following points:
1. It is better to use queryout when writing a query statement for export. I cannot use queryout when I use out.
2. The database name contains spaces,-, and other characters in the format of "[]". This online help is in use.
3. The file used for import must be the same as the file generated during export. Otherwise, the copy fails. By default, the imported file is a tab-separated file, the files generated by DTs use a lot of quotation marks or parentheses to separate fields. Therefore, the text exported by DTs and the text exported by BCP cannot be universal, otherwise, the "unexpected EOF encountered in the BCP data file" error will occur.
As follows:
Null
Start copying...
Sqlstate = s1000, nativeerror = 0
Error = [Microsoft] [odbc SQL Server Driver] unexpected EOF in BCP Data File
Null
0 rows have been copied.
Packet size (bytes): 4096
Clock Time (MS): 1 in total
Null
After the imported text is changed to the text generated by the export statement, it is finally successful.
4. A problem is found in tests on other machines. If the database structure of B is inconsistent with that of a, a "character shape error" may occur.
--------------
Before importing data to the machine of B, you must clear the data before B. Otherwise, a keyword conflict may occur. In this case, you must handle the foreign key constraint. Otherwise, an error may occur.
Clean up data on the B surface.
Osql-U "sa"-P "pass"-s "127.0.0.1"-Q "use customer Delete from order where fieldname = '****'"
Then execute the Import Statement.
BCP customer .. order in c: \ test.txt-C-s "192.168.102.122"-U sa-P pass
Write these two statements into the BAT file. Then place the test.txt file exported by a in a folder and click the BAT file to execute it.
Note: osql and BCP tools cannot be found on some machines. It may be that some machine environment variables are not set. I have to add these two tools, BCP, and resource DLL. I am too lazy to find them. It should be in the 80 \ tools \ binn directory of the sqlserver directory.