2 messages in com.mysql.lists.win32Primary Key Question| From | Sent On | Attachments |
|---|---|---|
| Keith Russell | 15 Apr 2004 21:02 | |
| Armando | 16 Apr 2004 11:22 |
| Subject: | Primary Key Question![]() |
|---|---|
| From: | Keith Russell (mys...@xemaps.com) |
| Date: | 04/15/2004 09:02:33 PM |
| List: | com.mysql.lists.win32 |
Hi again, everyone.
I'm trying to create the bookbiz database in "The Practical SQL Handbook", 2nd ed., by Judith S. Bowman, et al.
I'm almost done, but I've run into one problem:
One of the tables keeps track of royalty schedules, and was created as follows:
create table roysched (title_id char(6) not null, lorange int null, hirange int null, royalty float null);
The table has a single index created as follows:
create index titleidind on roysched (title_id);
Here are three rows that need to be entered in the table:
insert roysched values ('PC1035', 0, 2000, .10); insert roysched values('PC1035', 2001, 4000, .12); insert roysched values('PC1035', 4001, 50000, .16);
The problem is that the second and third entries are being rejected as duplicates. Apparently, MySQL is assuming that the first column is the primary key, although it isn't defined as such. Am I correct in assuming that this is what's happening?
Any suggestions as to the best way to get around this? As it is, I can't use a composite primary key because only one column is defined as not null. However, it seems to me that a row would be meaningless if the lorange or hirange column were null, so I'm inclined to change at lease lorange to not null and include it in the primary key.
Does this make sense? Any other ideas?
Thanks a lot for all the help everyone is giving me!
-- Keith




