用自定义的SQL脚本创建SQL Server数据库安装例子

Creating a Sample Installation that Creates a SQL Server Database by Running Customized SQL Script
InstallShield 2009
 用自定义的SQL脚本创建SQL Server数据库安装例子
Project 项目
This information applies to the following project types: 此信息是用于下面的项目类型
• Basic MSI
• InstallScript MSI
The following procedure demonstrates how to create an installation that creates a SQL Server database through customized SQL script.
下面的过程展示了如何用自定义的SQL脚本创建SQL Server数据库安装
Task 任务
To create an installation that creates a SQL Server database on the target machine by running customized SQL script:
1. Create a new Basic MSI or InstallScript MSI project.新建一个基本MSI安装脚本MSI工程。
2. In the View List under Behavior and Logic, click Property Manager.在视图列表下的行为和逻辑,点属性管理。
3. Create a new property that has the following name:新建属性名称为IS_SQLSERVER_DATABASE2
IS_SQLSERVER_DATABASE2
4. In the View List under Server Configuration, click SQL Scripts.在视图列表下的服务器配置中,点SQL 脚本。
5. Add and configure a new SQL connection:
加入和配置新的SQL连接;
a. Right-click the SQL Scripts explorer and click New SQL Connection. InstallShield adds a new connection with the name NewConnection1 as the default name.
b. In the SQL Scripts explorer, click the NewConnection1 item, and then click the General tab.
c. In the Default Target Server Name (optional) box, type TESTSQLSERVER.
d. Clear the Create Catalog If Absent check box.
e. In the Connect using area, select the Server authentication using the Login ID and password below option.
f. In the Login ID box, type sa. Leave the Password box blank.
g. Click the Requirements tab.
h. Ensure that the Microsoft SQL Server check box is selected and the MySQL and Oracle check boxes are cleared.
6. Add and configure a new SQL script for NewConnection1:
为NewConnnection1加入和配置新的SQL脚本
a. In the SQL Scripts explorer, right-click NewConnection1 and click New Script.
b. Change the name of the script to NewScript1.
c. In the SQL Scripts explorer, click NewScript1, and then click the Script tab.
d. In the script editor pane, add the following script:
CREATE DATABASE [TestDB] ON (NAME = N' TestDB', FILENAME = N'C:/Program Files/Microsoft SQL Server/MSSQL/data/testdb.mdf' , SIZE = 3, FILEGROWTH = 10%) LOG ON (NAME = N' TestDB_log', FILENAME = N'C:/Program Files/Microsoft SQL Server/MSSQL/data/testdb.ldf' , SIZE = 1, FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
e. Click the Runtime tab.
f. In the Script Execution area, select the Run Script During Login check box and ensure that the Run Script During Install and Run Script During Uninstall check boxes are cleared.
7. Add and configure a second new SQL connection:
加入和配置第二个SQL连接
a. Right-click the SQL Scripts explorer and click New SQL Connection. InstallShield adds a new connection with the name NewConnection2 as the default name.
b. In the SQL Scripts explorer, click the NewConnection2 item, and then click the Advanced tab.
c. In the Target Catalog Property Name list, select IS_SQLSERVER_DATABASE2.
d. Click the General tab.
e. In the Catalog Name box, type TestDB.
f. Clear the Create Catalog If Absent check box.
g. In the Default Target Server Name (optional) box, type TESTSQLSERVER.
h. In the Connect using area, select the Server authentication using the Login ID and password below option.
i. In the Login ID box, type sa. Leave the Password box blank.
j. Click the Requirements tab.
k. Ensure that the Microsoft SQL Server check box is selected and the MySQL and Oracle check boxes are cleared.
8. Add and configure a new SQL script for NewConnection2:
为NewConnnection2加入和配置新的SQL脚本
a. In the SQL Scripts explorer, right-click NewConnection2 and click New Script.
b. Change the name of the script to NewScript2.
c. In the SQL Scripts explorer, click NewScript2, and then click the Script tab.
d. In the script editor pane, add the following script:
CREATE TABLE TestTable (TestColumn1 CHAR NOT NULL PRIMARY KEY)
e. Click the Runtime tab.
f. In the Script Execution area, select the Run Script During Install check box and ensure that the Run Script During Login and Run Script During Uninstall check boxes are cleared.
When you run the installation, it creates the TestDB database and adds a table called TestTable to that database.
运行安装,创建数据库TestDB,并在库中创建名称为TestTable的表。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮你回答这个问题。下面是一些基本的SQL Server数据库操作: 1. 创建数据库:使用CREATE DATABASE语句可以在SQL Server创建一个新的数据库。例如: ``` CREATE DATABASE MyDatabase; ``` 2. 查询数据库:使用SELECT语句可以查询数据库的数据。例如: ``` SELECT * FROM MyDatabase.dbo.MyTable; ``` 这个查询语句将返回MyDatabase数据库dbo架构下的MyTable表的所有数据。 3. 维护数据库SQL Server提供了多种维护数据库的工具和技术,例如备份和还原数据库、优化数据库性能等。以下是一些常用的维护操作: - 备份数据库:使用BACKUP DATABASE语句可以备份整个数据库。例如: ``` BACKUP DATABASE MyDatabase TO DISK = 'C:\Backup\MyDatabase.bak'; ``` 这个语句将MyDatabase数据库备份到C:\Backup\MyDatabase.bak文件。 - 还原数据库:使用RESTORE DATABASE语句可以还原备份的数据库。例如: ``` RESTORE DATABASE MyDatabase FROM DISK = 'C:\Backup\MyDatabase.bak'; ``` 这个语句将从C:\Backup\MyDatabase.bak文件还原MyDatabase数据库。 - 优化数据库性能:SQL Server提供了多种性能优化技术,例如索引、分区、查询优化等。其,索引是最常用的优化技术之一。例如: ``` CREATE INDEX IX_MyTable_Column1 ON MyDatabase.dbo.MyTable(Column1); ``` 这个语句将在MyTable表的Column1列上创建一个新的索引。 以上是一些基本的SQL Server数据库操作,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值