A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Required property of Primary Key fields



 
 
Thread Tools Display Modes
  #1  
Old September 3rd, 2007, 07:53 AM posted to microsoft.public.access.tablesdbdesign
samah
external usenet poster
 
Posts: 31
Default Required property of Primary Key fields

Access Novice - WinXp/Access 2003.

I am a self taught access newbie. I have spent almost a year browsing
these newsgroups as a daily ritual. Although these newsgroups have given a
lot of enlightenment to a Access dummy, I am still not able to get a
complete grip on it. So here is what seems to be another stupid question
(at least after spending so much time on Access!).

All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.

May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.

Thank you in advance.

-samah



  #2  
Old September 3rd, 2007, 08:30 AM posted to microsoft.public.access.tablesdbdesign
scubadiver
external usenet poster
 
Posts: 1,673
Default Required property of Primary Key fields


I would have thought a primary key is always required if a table is related
to another (if that is what you are asking). Otherwise how can the records be
related to each other?

--

http://www.ready4mainstream.ny911truth.org/index.html


"samah" wrote:

Access Novice - WinXp/Access 2003.

I am a self taught access newbie. I have spent almost a year browsing
these newsgroups as a daily ritual. Although these newsgroups have given a
lot of enlightenment to a Access dummy, I am still not able to get a
complete grip on it. So here is what seems to be another stupid question
(at least after spending so much time on Access!).

All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.

May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.

Thank you in advance.

-samah




  #3  
Old September 3rd, 2007, 09:04 AM posted to microsoft.public.access.tablesdbdesign
samah
external usenet poster
 
Posts: 31
Default Required property of Primary Key fields

scubadiver wrote:
I would have thought a primary key is always required if a table is related
to another (if that is what you are asking). Otherwise how can the records be
related to each other?


Thank you scubadiver. In Northwind sample database there are 8 tables.
In 6 of the tables Primary Key is set to autonumber, so the Required
Property is not applicable. Please take a look at the other 2 tables.

Table Primary Key Data Type Required Property
Customers CustomerID Text No

OrderDetails OrderID Number No
ProductID Number Yes

-samah

  #4  
Old September 3rd, 2007, 09:11 AM posted to microsoft.public.access.tablesdbdesign
samah
external usenet poster
 
Posts: 31
Default Required property of Primary Key fields

scubadiver wrote:
I would have thought a primary key is always required if a table is related
to another (if that is what you are asking). Otherwise how can the records be
related to each other?


.... and you misunderstood my question. It is not about the Primary Key
itself. It is about the Required Property of the Primary Key. Both are
different if I am not mistaken.

Thank you.

-samah
  #5  
Old September 3rd, 2007, 11:57 AM posted to microsoft.public.access.tablesdbdesign
Jamie Collins
external usenet poster
 
Posts: 1,705
Default Required property of Primary Key fields

On 3 Sep, 07:53, samah wrote:
All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.

May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.


While you can indeed use PRIMARY KEY designation for nullable columns
(Required = No) in Jet, you will not be able to set any of the the
PRIMARY KEY columns to be the NULL value. IMO this is a bug e.g. SQL
Server will generate an error when attempting to create a PK on
nullable columns.

If you need columns to be nullable, use a UNIQUE constraint (Index no
duplicates) instead, which can still be used for FOREIGN KEY
references.

Jamie.

--


  #6  
Old September 3rd, 2007, 02:27 PM posted to microsoft.public.access.tablesdbdesign
samah
external usenet poster
 
Posts: 31
Default Required property of Primary Key fields

Jamie Collins wrote:
On 3 Sep, 07:53, samah wrote:
All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.

May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.


While you can indeed use PRIMARY KEY designation for nullable columns
(Required = No) in Jet, you will not be able to set any of the the
PRIMARY KEY columns to be the NULL value. IMO this is a bug e.g. SQL
Server will generate an error when attempting to create a PK on
nullable columns.

If you need columns to be nullable, use a UNIQUE constraint (Index no
duplicates) instead, which can still be used for FOREIGN KEY
references.

Jamie.

--



Jamie, thank you for the insight.

If I don't need columns to be nullable, can I assume that setting the
PRIMARY KEY field's Required Property to YES or NO doesn't make any
difference?

What about a composite PRIMARY KEY consisting of two FOREIGN KEYS? If I
set the keys' Required Property both to YES, both to NO or one to YES
and the other to NO, will it make any difference?

Thank you in advance.

-samah






  #7  
Old September 3rd, 2007, 04:00 PM posted to microsoft.public.access.tablesdbdesign
Jamie Collins
external usenet poster
 
Posts: 1,705
Default Required property of Primary Key fields

On 3 Sep, 14:27, samah wrote:
Jamie Collins wrote:
On 3 Sep, 07:53, samah wrote:
All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.


May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.


While you can indeed use PRIMARY KEY designation for nullable columns
(Required = No) in Jet, you will not be able to set any of the the
PRIMARY KEY columns to be the NULL value. IMO this is a bug e.g. SQL
Server will generate an error when attempting to create a PK on
nullable columns.


If you need columns to be nullable, use a UNIQUE constraint (Index no
duplicates) instead, which can still be used for FOREIGN KEY
references.


Jamie.


--


Jamie, thank you for the insight.

If I don't need columns to be nullable, can I assume that setting the
PRIMARY KEY field's Required Property to YES or NO doesn't make any
difference?


The difference is between the SQL update (INSERT/UPDATE) failing a NOT
NULL constraint and failing a PRIMARY KEY constraint. In either case
the net result is the same i.e. the SQL update fails.

I say, make the columns NOT NULL (Required = Yes).

What about a composite PRIMARY KEY consisting of two FOREIGN KEYS? If I
set the keys' Required Property both to YES, both to NO or one to YES
and the other to NO, will it make any difference?


It makes no difference.

IMO nullable columns should be avoided, especailly in FKs.

Jamie.

--




  #8  
Old September 3rd, 2007, 04:45 PM posted to microsoft.public.access.tablesdbdesign
tina
external usenet poster
 
Posts: 1,997
Default Required property of Primary Key fields

All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'.


i would agree that single-field primary keys should always be Required =
Yes. as for composite keys, i suppose it's possible that a valid value for
all but one of the individual fields in the key might be Null, but that
seems odd to me - and difficult to enforce. my recommendation would be that
you do not use fields that may contain a Null value as single or composite
primary keys.

But after started
exploring a few sample databases in depth, I realized it is not so.


keep in mind that Microsoft's sample databases (and no doubt other sample
dbs as well) are not always written perfectly. just because you see
something in a sample db, that doesn't necessarily mean it's the best - or
even correct - design.

hth


"samah" wrote in message
...
Access Novice - WinXp/Access 2003.

I am a self taught access newbie. I have spent almost a year browsing
these newsgroups as a daily ritual. Although these newsgroups have given a
lot of enlightenment to a Access dummy, I am still not able to get a
complete grip on it. So here is what seems to be another stupid question
(at least after spending so much time on Access!).

All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.

May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.

Thank you in advance.

-samah





  #9  
Old September 3rd, 2007, 06:07 PM posted to microsoft.public.access.tablesdbdesign
samah[_2_]
external usenet poster
 
Posts: 12
Default Required property of Primary Key fields

Jamie Collins wrote:
On 3 Sep, 14:27, samah wrote:
Jamie Collins wrote:
On 3 Sep, 07:53, samah wrote:
All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.
May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.
While you can indeed use PRIMARY KEY designation for nullable columns
(Required = No) in Jet, you will not be able to set any of the the
PRIMARY KEY columns to be the NULL value. IMO this is a bug e.g. SQL
Server will generate an error when attempting to create a PK on
nullable columns.
If you need columns to be nullable, use a UNIQUE constraint (Index no
duplicates) instead, which can still be used for FOREIGN KEY
references.
Jamie.
--

Jamie, thank you for the insight.

If I don't need columns to be nullable, can I assume that setting the
PRIMARY KEY field's Required Property to YES or NO doesn't make any
difference?


The difference is between the SQL update (INSERT/UPDATE) failing a NOT
NULL constraint and failing a PRIMARY KEY constraint. In either case
the net result is the same i.e. the SQL update fails.

I say, make the columns NOT NULL (Required = Yes).

What about a composite PRIMARY KEY consisting of two FOREIGN KEYS? If I
set the keys' Required Property both to YES, both to NO or one to YES
and the other to NO, will it make any difference?


It makes no difference.

IMO nullable columns should be avoided, especailly in FKs.

Jamie.

--





Thank you for your time and guidance, Jamie.

-samah
  #10  
Old September 3rd, 2007, 06:11 PM posted to microsoft.public.access.tablesdbdesign
samah[_2_]
external usenet poster
 
Posts: 12
Default Required property of Primary Key fields

Thank you, tina.

-samah


tina wrote:
All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'.


i would agree that single-field primary keys should always be Required =
Yes. as for composite keys, i suppose it's possible that a valid value for
all but one of the individual fields in the key might be Null, but that
seems odd to me - and difficult to enforce. my recommendation would be that
you do not use fields that may contain a Null value as single or composite
primary keys.

But after started
exploring a few sample databases in depth, I realized it is not so.


keep in mind that Microsoft's sample databases (and no doubt other sample
dbs as well) are not always written perfectly. just because you see
something in a sample db, that doesn't necessarily mean it's the best - or
even correct - design.

hth


"samah" wrote in message
...
Access Novice - WinXp/Access 2003.

I am a self taught access newbie. I have spent almost a year browsing
these newsgroups as a daily ritual. Although these newsgroups have given a
lot of enlightenment to a Access dummy, I am still not able to get a
complete grip on it. So here is what seems to be another stupid question
(at least after spending so much time on Access!).

All this time I was under the misconception that Required Property of
primary keys and composite primary keys consisting of two or more
foreign keys, should always be set to 'Yes'. But after started
exploring a few sample databases in depth, I realized it is not so.

May be I am missing a very important concept here and shall be thankful
if someone could shed some light on it.

Thank you in advance.

-samah






 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:17 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.