Keeping referential integrity (good programming?)

Results 1 to 4 of 4

Thread: Keeping referential integrity (good programming?)

  1. #1
    Troy Guest

    Default Keeping referential integrity (good programming?)

    Is it good programming to make a default record that can be used if no choice is selected? My test making system allows people to make questions for tests without choosing a correct answer immediately. If I leave the answer field blank in the insert statement, I get an error saying that it has to match an answer ID in the answer table (referential integrity). To keep referential integrity and the ability to cascade update, would it be ok to make a dummy record with its own id? This way instead of leaving the field blank, I could enter a “-1”, or something similar, to represent an unanswered question. <BR><BR>I have been told never to leave a field blank while making a record, so this is the only way I know to do this. If it was left blank, how do I check what is in the field without getting an error?<BR><BR>If there is any other way to do this please suggest, I am new to this and need any help you can give.<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Keeping referential integrity (good programmin

    Hi!<BR>Well, the first question is what kind on databases are you using.<BR>If you use access or sql server, you can define for any field that accept null values. Furthermore, you can define an ID field with the next properties: Not Null Values and Be an Identity Field. This way, the ID field always have an unique value, ant the other fields can be in blank.<BR><BR>I hope this can help you.<BR>

  3. #3
    jamar Guest

    Default may not be necessary...

    So you have a Question table and an Answer Table. A single question can have 0 -&#062; many answers? If so then, QuestionID should be a &#060;FK&#062; in the Answer Table and a record will not be required in the Answer Table. If I don&#039;t understand what you are trying to accomplish please correct me. <BR>As far as cascading update and deletes...etc. In order to delete a question you would need to delete all answers for that question first.

  4. #4
    Troy Guest

    Default RE: Keeping referential integrity (good programmin

    Thanks for the advice.<BR><BR>I am using an Access database. I understand what you are saying but how would I cascade update all of the values? Access gives and option to turn on referential integrity on. I have turned on to make updates easy. If I leave the answer field blank I get an error inserting the new record because null is not defined in the answer table. <BR><BR>Is there a way to keep this integrity? If I change a correct answser I want to be able to update all of the relating records.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts