473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I handle this referential integrity situation?

Using 2003. I've got a simple 1:M relationship for employees and
classifications. A classification can be assigned to many employees/an
employee can only have one classification. I created a form for adding
employees/classifications. The classification can be left blank if not
known. I created a 2nd form for modifying employees/classification.
If the classification is left blank, or it's blank out, the 3201
referential integrity error occurs. I understand that there is not a
blank record in the classifications table so that's why the error. But
is there a way to leave the classification blank or blank it out? Do I
have to put a record in the classifications lookup table, like (no
classification)? Thanks for any help or advice.

Jan 6 '06 #1
14 2137
if an employee can have no classification (and it's valid), then you
can't enforce referential integrity between employees and
classifications. If you set the RI constraint to none, then everything
will be fine.

Jan 6 '06 #2
<ma**********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Using 2003. I've got a simple 1:M relationship for employees and
classifications. A classification can be assigned to many employees/an
employee can only have one classification. I created a form for adding
employees/classifications. The classification can be left blank if not
known. I created a 2nd form for modifying employees/classification.
If the classification is left blank, or it's blank out, the 3201
referential integrity error occurs. I understand that there is not a
blank record in the classifications table so that's why the error. But
is there a way to leave the classification blank or blank it out? Do I
have to put a record in the classifications lookup table, like (no
classification)? Thanks for any help or advice.

This is perfectly possible - just as you describe - without any need to
define a 'no classification' record in the classifications table. There is
something else you are doing wrong.
My guess is that you have something like
tblEmployee.ClassificationID which is a long integer with a default value of
zero. When you create the record, it tries to put zero in this field, and
of course you don't have a matching record where tblCalssification.ID=0.
So, certainly check any default values in your table design.
Jan 6 '06 #3
<pi********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
if an employee can have no classification (and it's valid), then you
can't enforce referential integrity between employees and
classifications. If you set the RI constraint to none, then everything
will be fine.

Are you sure of what you are saying?
Jan 6 '06 #4
pi********@hotmail.com wrote in
news:11**********************@z14g2000cwz.googlegr oups.com:
if an employee can have no classification (and it's valid), then
you can't enforce referential integrity between employees and
classifications. If you set the RI constraint to none, then
everything will be fine.


Eh? All you need is for the foreign key to not be required. That
way, the FK can be Null, while still enforcing that any non-Null
value will be drawn from the PK of a related table.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jan 6 '06 #5
if an employee can have no classification (and it's valid), then you
can't enforce referential integrity between employees and
classifications. If you set the RI constraint to none, then everything
will be fine.

If you choose to enforce RI, then you have to classify each employee.
That's the way RI works...

Jan 7 '06 #6
There's no default value. For the user's benefit I store the
description, not an ID #.
Anthony England wrote:
<ma**********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Using 2003. I've got a simple 1:M relationship for employees and
classifications. A classification can be assigned to many employees/an
employee can only have one classification. I created a form for adding
employees/classifications. The classification can be left blank if not
known. I created a 2nd form for modifying employees/classification.
If the classification is left blank, or it's blank out, the 3201
referential integrity error occurs. I understand that there is not a
blank record in the classifications table so that's why the error. But
is there a way to leave the classification blank or blank it out? Do I
have to put a record in the classifications lookup table, like (no
classification)? Thanks for any help or advice.

This is perfectly possible - just as you describe - without any need to
define a 'no classification' record in the classifications table. There is
something else you are doing wrong.
My guess is that you have something like
tblEmployee.ClassificationID which is a long integer with a default value of
zero. When you create the record, it tries to put zero in this field, and
of course you don't have a matching record where tblCalssification.ID=0.
So, certainly check any default values in your table design.


Jan 7 '06 #7
There has to be a way to do this. I haven't tried this but I could
trap the error. But once it's trapped can I tell the mdb to ignore it
and leave the field blank?

Jan 7 '06 #8

<ma**********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
There's no default value. For the user's benefit I store the
description, not an ID #.
Anthony England wrote:
<ma**********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
> Using 2003. I've got a simple 1:M relationship for employees and
> classifications. A classification can be assigned to many employees/an
> employee can only have one classification. I created a form for adding
> employees/classifications. The classification can be left blank if not
> known. I created a 2nd form for modifying employees/classification.
> If the classification is left blank, or it's blank out, the 3201
> referential integrity error occurs. I understand that there is not a
> blank record in the classifications table so that's why the error. But
> is there a way to leave the classification blank or blank it out? Do I
> have to put a record in the classifications lookup table, like (no
> classification)? Thanks for any help or advice.

This is perfectly possible - just as you describe - without any need to
define a 'no classification' record in the classifications table. There
is
something else you are doing wrong.
My guess is that you have something like
tblEmployee.ClassificationID which is a long integer with a default value
of
zero. When you create the record, it tries to put zero in this field,
and
of course you don't have a matching record where tblCalssification.ID=0.
So, certainly check any default values in your table design.

If that is not the problem, then you could try and narrow down the cause of
the error. Without using any forms, but just entering data in the tables
directly, can you create an employee with no classification? If not then we
need to look at the table structure in greater detail. If you can, then it
is the form design at fault.
Jan 7 '06 #9
<pi********@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
if an employee can have no classification (and it's valid), then you
can't enforce referential integrity between employees and
classifications. If you set the RI constraint to none, then everything
will be fine.

If you choose to enforce RI, then you have to classify each employee.
That's the way RI works...

If you create the following tables:

tblContact:
ConID Autonumber, PK
ConName Text, Length 50, Required, Do not allow zero length, Indexed No
Duplicates
ConType Long Integer, Not Required, Indexed Duplicates OK

tblType:
TypID Autonumber, PK
TypName Text, Length 50, Required, Do not allow zero length, Indexed No
Duplicates
.... you can enforce RI with a one to many relationship between tblType and
tblContact. This means that each contact can have a type - it doesn't have
to, but if it does have one, then it must be one in the table tblType.
That's the way RI works on my machine - but let me know if you cannot
reproduce this structure on yours.
Jan 7 '06 #10
ma**********@hotmail.com wrote in
news:11**********************@f14g2000cwb.googlegr oups.com:
Using 2003. I've got a simple 1:M relationship for employees and
classifications. A classification can be assigned to many
employees/an employee can only have one classification. I created
a form for adding employees/classifications. The classification
can be left blank if not known. I created a 2nd form for
modifying employees/classification. If the classification is left
blank, or it's blank out, the 3201 referential integrity error
occurs. I understand that there is not a blank record in the
classifications table so that's why the error. But is there a way
to leave the classification blank or blank it out? Do I have to
put a record in the classifications lookup table, like (no
classification)?


Did you define the classification field as required?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jan 7 '06 #11
No, it's not required. Here's the table setup:

tblEmployees:
ID, autonumber, PK
LastName, text, 50
FirstName, text, 50
Classification, text, 50, not required, not indexed, zero-length
allowed

tlkpClassifications:
Classification, text, 50, PK

Jan 9 '06 #12
Forgot to add that I can enter an employee record directly into the
table, then blank out the classification. So it must be something in
the form design like Anthony England suggested. FWIW, it's an unbound
form. I use DAO to write to the employee table.

Jan 9 '06 #13
<ma**********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Forgot to add that I can enter an employee record directly into the
table, then blank out the classification. So it must be something in
the form design like Anthony England suggested. FWIW, it's an unbound
form. I use DAO to write to the employee table.


Well that makes a huge difference. If it is unbound then presumably the
error occurs when you try to save the record and not directly after you edit
the control (you don't say whether this is a textbox or combo or what).
There are a number of ways you could be trying to save the record and you
haven't posted any code.
Two things come to mind:
1. My current guess is that instead of null as the classification, which
would be allowed, you are trying to save a zero-length string.
2. Before anyone else asks: " are you really sure unbound forms are
offering you advantages over bound ones?"
Jan 9 '06 #14
1. Thanks. That was the problem

2. Poor choice on my part. There was no reason for it to be unbound.
I changed it to bound.
Anthony England wrote:
<ma**********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Forgot to add that I can enter an employee record directly into the
table, then blank out the classification. So it must be something in
the form design like Anthony England suggested. FWIW, it's an unbound
form. I use DAO to write to the employee table.


Well that makes a huge difference. If it is unbound then presumably the
error occurs when you try to save the record and not directly after you edit
the control (you don't say whether this is a textbox or combo or what).
There are a number of ways you could be trying to save the record and you
haven't posted any code.
Two things come to mind:
1. My current guess is that instead of null as the classification, which
would be allowed, you are trying to save a zero-length string.
2. Before anyone else asks: " are you really sure unbound forms are
offering you advantages over bound ones?"


Jan 9 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob Rogers | last post by:
I seem to have gotten myself into a bit of a pickle. I am trying to delete a record from a table attached to a form, and it complains about not being able to delete a record in a table because...
3
by: Dave | last post by:
I have always taken it for granted that once RI is in place, no orphan records can be created, and that RI can't be put in place while orphans exist, but today I came across a situation where that...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
7
by: Jimmie H. Apsey | last post by:
Referential Integrity on one of our production tables seems to have been lost. I am running Postgres 7.1.3 embedded within Red Hat kernel-2.4.9-e.49. Within that I have a table with referential...
6
by: heyvinay | last post by:
I have transaction table where the rows entered into the transaction can come a result of changes that take place if four different tables. So the situation is as follows: Transaction Table...
80
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used...
6
by: CPAccess | last post by:
How do I maintain referential integrity between a main form and a subform, each based upon different (but joined with integrity enforced) table? Here's the situation: I have two tables:...
3
by: Wayne | last post by:
I've inadvertently placed this post in another similar newgroup, and I apologise if you get it twice. I'm building a database that consists of frontend and backend. Some of the lookup tables...
2
by: ApexData | last post by:
Access2000, using a continuous form. I’m getting a message that say “you cannot add or change a record because a related record is required in table Employee”. This occurs in all my combobox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.