KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to enable replication
PRODUCT: 4D | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: April 29, 2011

Replication and Synchronization are deep topics which take quite a bit of practice and research to fully understand, but the first step is easy. To enable Replication two steps need to be taken: set a primary key for the table and turn on Replication. There are two ways to to do each of these, in code or in the Structure Editor.

In the Structure Editor:

First find the field you want to use as a primary key. Right click and choose "Create primary key" as shown below:



Once you have created a primary key you can enable replication. Go to the table Inspector and check the box "Enable Replication" as shown below:



This check box is only enabled if the table has a primary key.

In Code:

You can set a primary key for a table programmatically via SQL. It can either be managed when creating the table in SQL or via the ALTER TABLE command in SQL. Both instances are shown below:

When creating the table there are two ways to do this:

Begin SQL
   CREATE TABLE replicator2
   (prikey varchar(30),
   name varchar(30),
   address varchar(30),
   PRIMARY KEY (prikey));

End SQL


or:
Begin SQL
   CREATE TABLE replicator2
   (prikey varchar(30) PRIMARY KEY,
   name varchar(30),
   address varchar(30));

End SQL


When using an existing table there is one way:
Begin SQL
  ALTER TABLE replicator1 ADD PRIMARY KEY (prikey);
End SQL


Once a primary key has been set enabling replication is easy. It is handled with the ENABLE REPLICATE keyword in SQL used with CREATE TABLE or ALTER TABLE. Simply add one line to the examples above, as shown here:

Creating a new table:
Begin SQL
   CREATE TABLE replicator3
   (prikey varchar(30),
   name varchar(30),
   address varchar(30),
   PRIMARY KEY (prikey))
   ENABLE REPLICATE;

End SQL


Using an existing table:
Begin SQL
  ALTER TABLE replicator3 ADD PRIMARY KEY (prikey);
  ALTER TABLE replicator3 ENABLE REPLICATE;

End SQL


The Third Step:

Above it says that there are only two steps to enable Replication. That's accurate, but there's a third step that you might want to take immediately after enabling it: touch your data. See the Tech Tip "The Last Step in Replication: Touch Your Data" to find out how to do that.