Deleting data in a field

G

Guest

Ok, so I have a database with a comments table where there is an ID field and
a Comment field, both of which are foreign keys. The table is in a one to
many relationship with the main table (comments table is the many side). So a
user can enter several comments about one item. But if the user wants to
delete a comment, they can't. An error comes up saying "Index or primary key
cannot contain a null value"

How can I change this, so that users can delete comments once the comment is
no longer needed.

Thanks for the help in advance.

-Justin
 
A

Al Camp

Justin,
Change Comments from a key field to a normal field. You should only be
linking multiple Comments to another table via the ID field... not ID AND
Comments.
 
G

Guest

I've tried that, and it doesn't work. I get an error which says, "The changes
you requested to the table were not successful because they would create
duplicate values in the index, primary key, or relationship. Change the data
in the field or fields that contain duplicate data, remove the index, or
redefine the index to permit duplicate entries and try again."

so what should I try doing?
 
S

SusanV

Justin -

Is the ID field the foreign key to the main table? If so, you should add
another unique field to the Comments table for a primary key, as the
one-to-many relationship is going to create multiple records in the Comments
table for each ID.
 
G

Guest

SusanV said:
Justin -

Is the ID field the foreign key to the main table? If so, you should add
another unique field to the Comments table for a primary key, as the
one-to-many relationship is going to create multiple records in the Comments
table for each ID.


Yes, the ID field is the foreign key linked to the main table in a one to
many relationship. Ok, so I should create another unique field, make it the
primary key, and remove the ID field as a foreign key? But keep it linked in
the relationship?
 
S

SusanV

Hi Justin,

Yes, keep the existing ID filed as the foreign key to the main table, and
add another field as primary key. Easiest field type would be autonumber, as
you don't really care about what's *in* this new field so long as it's
unique. This new field should be the primary key, as a single field.
 
G

Guest

SusanV said:
Hi Justin,

Yes, keep the existing ID filed as the foreign key to the main table, and
add another field as primary key. Easiest field type would be autonumber, as
you don't really care about what's *in* this new field so long as it's
unique. This new field should be the primary key, as a single field.



SusanV,

Thank you so much!

-Justin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top