...Note the error at: alterInstructor.
I create the instructor table then the booking table. The instructor table has book_num FK. After the booking table is created I run the script alterTable to alter the instructor table.
Note: the alterPayee script runs fine but the book_num is a different data type. Is this a problem? It creates the database but it says there is an error when it tries to alter the instructor table....
Well, you are showing that much sql code except the most important script which do the ALTER TABLE ....
You should consider:
1. All your table should have primary keys, at least the table where a foreign key is referencing to must have one. That is book_num must be primary key of booking table.
2. Theorder of ALTER statements is important: The object a reference points to must already exist. So the order should be: Alter table booking ADD primary key... ; Alter table instructor ADD foreign key ... ;
3. Whether different datatypes are significant or not depends on whether the database is able to do the converting automatically. If not possible, you need an cast() explicitly. If the datatypes are too different, also cast() won't work. You should read and understand derby manual about the compatibility and (automatical) typecasting of DTs.
4. If you have inserted some data before defining foreign keys, sometimes this is impossible depending on already existing constraints (e.g. NOT NULL etc). Also order is here important: a book_num referenced in instructor table by foreign key must already exists in booking table.
5. Derby, JavaDB, Cloudscape they all also understand conventional definition of primary and foreign key constraints:
-- table x must be created first!
create table x(a int not null, b char, primary key (a));
-- now table x can be referenced in table y:
create table y(c int not null, d char, e int,
primary key (c), foreign key (e) references x on delete cascade); btw, it would be really simpler to help you if you also post the alter statements!
btw2, which column of instructor table should reference to table booking (book_num) ? Furthermore, which column of table booking is that book_num? your create table statements do not contain that information at all !
you can also look at your older posting.
-- tesu