Setting PK as not nullable via code

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
 
A

Allen Browne

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
 
D

David W. Fenton

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.
 

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