In the Informix Environment, add fields to an existing data table and adjust the primary key constraint of the data table.
In the Informix database environment, add fields to an existing data table and adjust the primary key constraint of the data table. The procedure is as follows:
(1) Add a field to an existing table:
SQL Syntax: ALTER TABLE table_name add column_name column_type optional_restriction;
For example, alter table x_user add zip_code integer default 1000;
Note: If the newly added field needs to be added to the primary key constraint and existing data in the original data table, the new field must have a default value. Otherwise, the Operation will fail.
(2) query the name of the primary key constraint of an existing table:
SQL Syntax: Select constrname from sysconstraints where constrtype = 'P'
And Tabid = (select Tabid from tables Ables where tabname = 'table _ name ');
(3) Drop primary key constraints for the original table:
SQL Syntax: ALTER TABLE table_name drop constraint primary key constraint name; // The value queried in (2)
(4) reset the primary key constraint:
SQL Syntax: ALTER TABLE table_name add constraint primary key (col_name1, col_name2,...) [constrain primary key constraint name];
// The primary key constraint name can be the original name, and the value queried in (2)