Friday, July 3, 2009

DERBY-4244: A statement makes the problem

I did the following tests,

Without, alter table t0 add column c1 int;

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


It succeed.

Conclusion:Though the statement alter table t0 add column c2 int not null default 0 primary key; did not affect on the table to create a column. It effect on the following codes.

To see test what codes it effects, We did the following test, With the a small change of the second statement

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