These instructions assume that you are using DB2 Universal Database and guide you through the following tasks:
The following tasks are optional:
Complete the following steps:
On Windows:
You must replace install_dir with the path to your DB2 product installation directory, such as C:\PROGRA~1\IBM\SQLLIB. You can find this location by using the db2level command:CREATE DB DBINPUT CONNECT TO DBINPUT BIND 'install_dir\bnd\@db2cli.lst' blocking all grant public TERMINATE
On Linux:
You must replace install_dir with the path to your DB2 product installation directory. You can find this location by using the db2level command:CREATE DB DBINPUT CONNECT TO DBINPUT BIND install_dir/bnd/@db2cli.lst grant public CLIPKG 5 TERMINATE
db2start
db2 -vf dbinput.sql
Next: Choose one of the following options to create the database tables and triggers:
Note. When you create and access the database tables, be aware of the following issues:
Create the database tables and triggers:
CONNECT TO DBINPUT@ DROP TABLE "DBINPUT_CUSTOMER"@ CREATE TABLE "DBINPUT_CUSTOMER" ( "PKEY" VARCHAR(10) NOT NULL, "FIRSTNAME" VARCHAR(20), "LASTNAME" VARCHAR(20), "CCODE" VARCHAR(10) ) DATA CAPTURE NONE@ DROP TABLE "DBINPUT_EVENTS"@ CREATE TABLE "DBINPUT_EVENTS" ( "EVENT_ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 NO CYCLE NO CACHE), "OBJECT_KEY" VARCHAR(80) NOT NULL, "OBJECT_VERB" VARCHAR(40) NOT NULL ) DATA CAPTURE NONE@ ALTER TABLE "DBINPUT_CUSTOMER" ADD CONSTRAINT "DBINPUTCUSTOMERPK" PRIMARY KEY ("PKEY")@ ALTER TABLE "DBINPUT_EVENTS" ADD CONSTRAINT "DBINPUTEVENTPK" PRIMARY KEY ("EVENT_ID")@ CREATE TRIGGER "DBIN_CUST_CREATE" AFTER INSERT ON "DBINPUT_CUSTOMER" REFERENCING NEW AS N FOR EACH ROW INSERT INTO DBINPUT_EVENTS (OBJECT_KEY, OBJECT_VERB) VALUES (N.pkey, 'Create')@ CREATE TRIGGER "DBIN_CUST_DELETE" AFTER DELETE ON "DBINPUT_CUSTOMER" REFERENCING OLD AS O FOR EACH ROW INSERT INTO DBINPUT_EVENTS (OBJECT_KEY, OBJECT_VERB) VALUES (O.pkey, 'Delete')@ CREATE TRIGGER "DBIN_CUST_UPDATE" AFTER UPDATE ON "DBINPUT_CUSTOMER" REFERENCING NEW AS N FOR EACH ROW INSERT INTO DBINPUT_EVENTS (OBJECT_KEY, OBJECT_VERB) VALUES (N.pkey, 'Update')@ TERMINATE@
db2 -td@ -vf dbinput_create_tables_db2.sql
Wait for the script to finish running. If you are running the script for the first time, the following message is displayed twice:
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0204N "DB2ADMIN.DBINPUT_EVENTS" is an undefined name. SQLSTATE=42704Ignore both messages. The message is displayed because the script attempts to remove existing tables, DBINPUT_CUSTOMER and DBINPUT_EVENTS, before it creates the new tables, but if you have not run the script before, the script cannot find the existing tables.
If you are not running the script for the first time, you might see the following warning for each of the triggers:
SQL0280W View, trigger or materialized query table "DB2ADMIN.DBIN_CUST_UPDATE" has replaced an existing inoperative view, trigger or materialized query table. SQLSTATE=01595You can also ignore these messages.