Method for transplanting SQL Server

xiaoxiao2021-03-06  184

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

- Select "Generate All Objects", "In the script file, the illustrative title" is selected

- In the "Extended Properties", select

- In the "Table Check Options" all selected

- Among the "Security Options" is to determine whether you want to include settings for creating databases and user permissions, based on your needs

- 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

转载请注明原文地址:https://www.9cbs.com/read-128662.html

New Post(0)