After the application is developed by SQL Server, the software is deployed to the customer's computer, or the database is required to move the database to the server, and the application is operating at this time, usually There are many ways to re-transplant the database, and there are many ways to transplant. Summarize the following methods.
Prerequisites: Install SQL Server before installing your app.
method one:
Backup / recovery
First backup database:
Backup Database database to disk = 'c: / backup .bak'
Pack the backup file into the installer.
When running the program for the first time, the database recovery (or a system configured for a system configuration, to control the completion of this)
RESTORE DATABASE Database from Disk = 'C: / Backup .bak'
Method Two:
Separation / addition
Separate the database first:
sp_detach_db 'Database Name'
Pack the data file (.mdf) and log files (.LDF) into the installer
When running the program for the first time, the database is subjected to the database (or a system-configured program, to control the completion of this)
SP_ATTACH_DB 'Database Name,' Data File Name (.mdf) ',' Log File Name (.ldf) '
Method three
Database script
Generate a database script:
SQL200 Enterprise Manager
- Right click on the database to be exported
- All tasks
- Generate SQL scripts
-
-
-
-
- All other options keep default values
- then determine, save it into one. SQL file
Pack the script file into the installer.
When running the program for the first time, execute the script (or make a system configured program, to control the completion of this work), complete it by calling the isql.exe file.
Exec master..xp_cmdshell 'isql / e /i".sql file ""
Can also be called directly in the program
Isql.exe
file
.
Or directly
Isql.exe
Document integration into the program installation package