Change Views Quick Start with isql
Go Up to Change Views Quick Start
Contents
Creating a Subscription with isql
Subscriptions allow you to observe the changes on data across multiple connections, you can track changes like row inserts, updates, and deletes at a column-level.
In this guide you create subscriptions for the EMPLOYEE and CUSTOMER tables on the employee database.
To create a subscription using isql follow these steps:
- Connect to the
employeedatabase. - Create a subscription to track the changes on the employee table:
CREATE SUBSCRIPTION sub_employee_changes ON EMPLOYEE (EMP_NO, DEPT_NO, SALARY) DESCRIPTION 'Subscribe to changes in EMPLOYEE table';
- Create a subscription to track any delete operations on the customers table.
CREATE SUBSCRIPTION sub_customer_deletes ON CUSTOMER FOR ROW (DELETE) DESCRIPTION 'Subscribe to deletes in CUSTOMERS table';
- Verify the subscriptions are present running:
SHOW SUBSCRIPTIONS;
For more information on CREATE SUBSCRIPTION refer to Creating Subscriptions to Change Views and CREATE SUBSCRIPTION.
Granting Subscribe with isql
After creating a subscription you need to update its permissions so users can have access it and track changes. You can grant SUBSCRIBE privileges using the GRANT SUBSCRIBE statement.
You also need to activate the subscription using the SET SUBSCRIPTION statement. For more information refer to: Creating Subscriptions to Change Views, GRANT SUBSCRIBE, and SET SUBSCRIPTION.
Note: This guide employs the HRMANAGER user mentioned on the Before you Begin section.
To grant SUBSCRIBE to users using isql follow these steps:
- Make sure you are connected to the
employeedatabase. - Grant
SUBSCRIBEto user HRMANAGER on the "sub_employee_changes" subscription:GRANT SUBSCRIBE ON SUBSCRIPTION sub_employee_changes TO HRMANAGER;
- Grant
SUBSCRIBEto user HRMANAGER on the "sub_customer_deletes" subscription:GRANT SUBSCRIBE ON SUBSCRIPTION sub_customer_deletes TO HRMANAGER;
Setting Subscribe with isql
The SET SUBSCRIPTION statement sets a subscription as active or inactive, it also includes an optional AT clause to assign an ID or device name to the recipient of subscribed changes.
You can set a subscription using SET SUBSCRIPTION <subscription_name> [AT <destination>] {ACTIVE | INACTIVE};
For more information refer to: Creating Subscriptions to Change Views and SET SUBSCRIPTION.
To set a subscription with isql follow these steps:
- Make sure you are connected to the
employeedatabase. - Set a subscription with ID "device_1" for the "sub_employee_changes" subscription:
SET SUBSCRIPTION sub_employee_changes AT 'device_1' ACTIVE;
- Set a subscription with ID "device_1" for the "sub_customers_deletes" subscription:
SET SUBSCRIPTION sub_customers_deletes AT 'device_1' ACTIVE;