Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 入门 » MobiLink 教程 » 教程:编写脚本和监控同步

 

第 1 课:建立 SQL Anywhere 统一数据库

本课指导您通过以下步骤建立 SQL Anywhere 统一数据库:

  1. 创建统一数据库和模式。

  2. 运行 MobiLink 安装脚本。

  3. 为统一数据库定义 ODBC 数据源。

创建统一数据库

在此过程中,您将使用 Sybase Central 的 [创建数据库向导] 来创建统一数据库。

♦  创建 SQL Anywhere 数据库
  1. 选择 [开始] » [程序] » [SQL Anywhere 11] » [Sybase Central]。

  2. 选择 [工具] » [SQL Anywhere 11] » [创建数据库]。

  3. 在 [欢迎] 页面上,单击 [下一步]。

  4. 单击 [下一步]。

  5. 在 [将主数据库文件保存到以下文件] 字段中键入 C:\MLmon\cons.db。单击 [下一步]。

  6. 请按照 [创建数据库向导] 中的说明进行操作并接受缺省值。

  7. 单击 [完成]。

生成统一数据库模式

统一数据库模式包括 Product 表,其中存储硬件产品的名称和数量。

♦  将 Product 表添加到统一模式
  1. 在 Sybase Central 的左窗格中,右击 [cons - DBA],然后选择 [文件] » [打开 Interactive SQL]。

  2. 安装 Product 表。

    • 在 Interactive SQL 中执行以下命令。

      /* the Product table */
      create table Product (
          name    varchar(128) not null primary key,
          quantity      integer,
          last_modified timestamp default timestamp
      )
      go
      
      insert into Product(name, quantity)
        values ( 'Screwmaster Drill', 10);
      
      insert into Product(name, quantity)
        values ( 'Drywall Screws 10lb', 30);
      
      insert into Product(name, quantity)
        values ( 'Putty Knife x25', 12);
      
      go
  3. 安装用于冲突解决的临时表。

    第 6 课:创建冲突检测和解决脚本中,您将编写用于在发生冲突时将值插入这些表的脚本。

    /* the Product_old table */
    create table Product_old (
        name    varchar(128) not null primary key,
        quantity      integer,
        last_modified timestamp default timestamp
    )
    go
    
    /* the Product_new table */
    create table Product_new (
        name    varchar(128) not null primary key,
        quantity      integer,
        last_modified timestamp default timestamp
    )
    go
  4. 检验每个表是否都成功创建。

    • 例如,在 Interactive SQL 中执行以下命令来检验 Product 表的内容。

      select * from Product
  5. 运行 MobiLink 安装脚本来添加 MobiLink 需要的系统对象。

    • 在 [SQL 语句] 窗格中,键入:

    read "C:\Program Files\SQL Anywhere 11\MobiLink\setup\syncsa.sql"
为统一数据库定义 ODBC 数据源。

使用 SQL Anywhere 11 驱动程序为 cons 数据库定义 ODBC 数据源。

♦  为统一数据库定义 ODBC 数据源
  1. 选择 [开始] » [程序] » [SQL Anywhere 11] » [ODBC 管理器]。

  2. 单击 [用户 DSN] 选项卡,然后单击 [添加]。

  3. 在 [名称] 列表中,单击 [SQL Anywhere 11]。单击 [完成]。

  4. 在 [SQL Anywhere 11 的 ODBC 配置] 窗口中,进行以下操作:

    1. 单击 [ODBC] 选项卡。

    2. 在 [数据源名] 字段中,键入 sa_cons

    3. 单击 [登录] 选项卡。

    4. 在 [用户 ID] 字段键入 DBA

    5. 在 [口令] 字段中键入 sql

    6. 单击 [数据库] 选项卡。

    7. 在 [服务器名] 字段中键入 cons

    8. 在 [数据库文件] 字段中键入 C:\MLmon\cons.db

    9. 单击 [确定]。

  5. 单击 [确定]。

进一步阅读

有关使用 dbinit 命令行实用程序创建统一数据库的信息,请参见初始化实用程序 (dbinit)第 3 课:为同步创建脚本

有关统一数据库(包括非 SQL Anywhere RDBMS)的详细信息,请参见MobiLink 统一数据库

有关 Interactive SQL 的详细信息,请参见使用 Interactive SQL