After the application software development supported by SQL Server is completed on the local machine, the software should be deployed on the customer's computer, or the database should be transplanted to the server, and the application software should be operated on the client, at this time, we usually need to re-port the database. There are many methods to port the database. there are the following methods to summarize.
Prerequisites: Install SQL server before installing your application.
Method 1:
Backup/recovery
Back up the database first:
Backup database to disk = 'C:/backup. Bak'
Pack the backup file into the installer.
Recover the database when running the program for the first time (or create a system configuration program to control the completion of this task)
Restore database from disk = 'C:/backup. Bak'
Method 2:
Detach/Attach
Separate the database first:
Sp_detach_db 'database name'
Package the data file (. MDF) and log file (. LDF) into the installer.
Attach the database when running the program for the first time (or create a system configuration program to control and complete the work)
Sp_attach_db 'database name', 'Data file name (. MDF) ', 'Log file name (. LDF )'
Method 3
Use Database scripts
Generate database script:
Sql200 Enterprise Manager
-- Right-click the database to export
-- All tasks
-- Generate an SQL script
-- <General> select "generate all object scripts" and "include descriptive titles in script files ".
-- <Set format>, select "include extended attributes"
-- <Option>, select all content in "Table script option"
-- <Option>, "security option" determines whether to include the settings for creating databases and user permissions. Select
-- Keep default values for all other options
-- Then confirm and save it as a. SQL file.
Package the script file into the installer.
When the program is run for the first time, execute the script (or a specific system configuration program) to control the completion of the job, and use the isql.exe file to complete the job.
Exec master.. xp_mongoshell 'isql/e/I ". SQL file "'
You can also directly use the isql.exefile in the program or directly integrate the isql.exe file into the program installation package.