Data Replication with SQL Remote
PART 1. Introduction to SQL Remote
CHAPTER 4. A Tutorial for Adaptive Server Anywhere Users
The following sections are a tutorial describing how to set up a simple SQL Remote replication system in Adaptive Server Anywhere using Sybase Central.
You do not need to enter SQL statements if you are using Sybase Central to administer SQL Remote. A tutorial for those who do not have access to Sybase Central, or who prefer to work with command-line utilities, is presented in A tutorial using Interactive SQL and DBXTRACT, and contains the SQL statements executed behind the scenes by Sybase Central.
In this tutorial you act as the DBA of the consolidated database, and set up a simple replication system using the file-sharing message link. The simple example is a primitive model for a sales-force automation system, with two tables. One contains a list of sales representatives, and another a list of customers. The tables are replicated in a setup with one consolidated database and one remote database. You can install this example on one computer.
This tutorial assumes that you have some familiarity with Sybase Central. If you need help with Sybase Central, use the Sybase Central online Help.
This section describes the steps you need to take to prepare for the tutorial. These steps include the following:
Create the directories and databases required for the tutorial.
Add the tables to the consolidated database.
Create a directory to hold the files you make during this tutorial; for example c:\tutorial.
mkdir c:\tutorial
Create a subdirectory for each of the two user IDs in the replication system, to hold their messages. Create these subdirectories using the following statements at a system command line:
mkdir c:\tutorial\hq mkdir c:\tutorial\field
The tutorial uses two databases: a consolidated database named hq.db and a remote database named field.db. At this point, you should create the hq database with the Create Database utility in Sybase Central:
Start Sybase Central. You will be creating a new database so you do not have to connect to any particular existing database.
Click Utilities in the left panel.
Double-click Create Database in the right panel. The Create Database wizard is displayed.
Create a database with filename c:\tutorial\hq.db.
You can use the default settings for this database. Make sure you elect to maintain a transaction log. Replication cannot take place without a transaction log.
An Adaptive Server Anywhere database is simply a file, which can be copied to other locations and computers when necessary.
The next step is to add a pair of tables to the consolidated database.
Connect to the hq database from Sybase Central, as user ID DBA using password SQL.
Click the Tables folder of the hq database.
Double-click Add Table, and use the Table Editor to create a table named SalesRep with the following columns:
Key |
Column |
Data Type |
Size/Prec |
---|---|---|---|
Primary key |
rep_key |
char |
5 |
name |
char |
40 |
You do not need to use the Advanced Properties window. The columns are created by default not allowing NULL.
Double-click Add Table again, and use the Table Editor to create a table named Customer with the following columns:
Key |
Column |
Data Type |
Size/Prec |
---|---|---|---|
Primary key |
cust_key |
char |
10 |
name |
char |
40 |
|
rep_key |
char |
5 |
Again, you do not need to use the Advanced Properties window. The columns are created by default not allowing NULL.
Open the Foreign Keys folder of the Customer table container, and double-click Add Foreign Key. Using the Wizard, add a foreign key to the rep_key column of the SalesRep table. You can use the default settings for this foreign key.
You are now ready for the rest of the tutorial.