After I generate a script file db. SQL with the database structure and data, I want to restore the database on another computer for programming and testing. However, when I tried to execute the script on SQL Server manager Studio, the other party told me that the file was too large to open. After some searches, it is found that the following statements can be used through the command line to easily solve the problem. Note: If the script is too large, you can disable the stderr message to speed up execution.
OSQL-U sa-P-S (local) \ SQLExpress-d trw-r-I db. SQL
SQLExpress is my local database server, TRW is the database name, and db. SQL is my script file. The command parameters of the osql tool are as follows:
Osql [-U logon ID] [-P Password]
2 [-S server] [-H host name] [-E trusted connection]
3 [-d use the database name] [-l logon timeout value] [-t query timeout value]
4 [-h title] [-s column separator] [-w column width]
5 [-a packet size] [-e echo input] [-I allows the quotation mark identifier]
6 [-L list servers] [-c command end] [-d odbc dsn name]
7 [-q "command line query"] [-Q "command line query" and exit]
8 [-n delete number method] [-m error level]
9 [messages sent from-r to stderr] [-V severity level]
10 [-I input file] [-o output file]
11 [-p print statistics] [-B abort batch processing when an error occurs]
12 [-X [1] disable command, [display warning when exiting]
13 [-O disable the following items when using old ISQL]
14 <EOF> Batch Processing
15. automatically adjust the width of the console
16-width message
17 default error levels:-1 and 1
18 [-? Show syntax Summary]