Setting PK as not nullable via code

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I need to run through all table in the db and set the primary key in each as
not nullable. How can I achieve this via code?

Many Thanks

Regards
 
John said:
I need to run through all table in the db and set the primary key in each
as not nullable. How can I achieve this via code?

No need: if a field is (in) the primary key, it cannot be null.

It is actually possible to set the Required property of the field to Yes
using DAO code if you need to. Refer to:
CurrentDb.TableDefs("MyTable").Fields("MyField").Required
 
No need: if a field is (in) the primary key, it cannot be null.

In your standard Jet/ACE table created via the Access UI, that is
enforced by the index. I don't know if it's better to also set the
Required property or not. I think the validation rule (or required
property) fires before the check against the index, but I don't know
if that has any impact on performance or locks or anything.
 
Back
Top