ij> create table t0(c1 int not null constraint p1 primary key);
0 rows inserted/updated/deleted
ij> alter table t0 add column c2 int not null default 0 primary key;
ERROR X0Y58: Attempt to add a primary key constraint to table '"APP"."T0"' failed because the table already has a constr
aint of that type. A table can only have a single primary key constraint.
ij> alter table t0 add column c2 int not null default 0;
ERROR XSCH5: In a base table there was a mismatch between the requested column number 1 and the maximum number of column
s 2.
It didn't pass.
Without, alter table t0 add column c1 int; and alter table t0 add column c2 int not null default 0 primary key;
ij> create table t0(c1 int not null constraint p1 primary key);
0 rows inserted/updated/deleted
ij> alter table t0 add column c2 int not null default 0;
0 rows inserted/updated/deleted
ij> drop table t0;
0 rows inserted/updated/deleted
It succeed.
Without, alter table t0 add column c1 int; only
ij> create table t0(c1 int not null constraint p1 primary key);
0 rows inserted/updated/deleted
ij> alter table t0 add column c1 int;
ERROR X0Y32: Column 'C1' already exists in Table/View '"APP"."T0"'.
ij> alter table t0 add column c2 int not null default 0;
0 rows inserted/updated/deleted
ij> create table t0(c1 int not null constraint p1 primary key);
0 rows inserted/updated/deleted
ij> alter table t0 add column c3 int not null default 0 primary key;
0 rows inserted/updated/deleted
ij> alter table t0 add column c2 int not null default 0;
0 rows inserted/updated/deleted
It suceed the test.
Conclusion: When the statement alter table t0 add column c2 int not null default 0 primary key; executed(It gives a error), something remains in the database engine that can be effect on creating a new column which has the same name 'c2'.

No comments:
Post a Comment