472,993 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how do you programmatically create a relationship WITHOUT creating an index?

Hi gang,

Please help. I've been through the Access help, searched the Web, and
I can't seem to get a straight answer. As the Subject line suggests, I
want to run a fairly simple VB/Access Sub Function/Module that creates
relationships for my tables. The problem is that I need to provide for
some tables that may have > 32 relationships (which is apparently the
limit on Indexes that Access can support). How can I prevent Access
from automatically creating these indexes, AND still get referential
integrity, as viewable in my Relationships window. I started with
this, which works fine until the 32 index-limit is reached:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT [FKp_115]
FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

Then I read that this would work:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT NO INDEX
[FKp_115] FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

I tried the "NO INDEX" key phrase everywhere imaginable, as well as
with "As Database" using .Execute, still to no avail. Using DROP
obliterates the referential integrity altogether. I sincerely hope
SOMEONE knows what I can do, and hopefully it won't require a page of
code and importing or using all sorts of esoteric do-dads...what the
heck, I'll take any solution. HELP!!! Feel free to post and/or email
me directly. Thanks in advance, -Brian sa***@leapse.com
Nov 13 '05 #1
8 4260
Hi Brian.

If we are talking about JET here (i.e. if your tables are in an Access
database), you will not be able to do that. JET must have a unique index in
order to create a relationship with RI.

Your table may have some spurious indexes that you can dump. By default,
Access creates an index on any field that has a name ending in ID, Code,
Num, etc. (To avoid that: Tools | Options | Tables/Queries | Autoindex.)
These indexes are listed in the Indexes dialog (Tools menu) in table design,
and you can delete them there. Additionally Access creates hidden indexes on
all the foreign key fields that are involved in relationships with RI, so if
you manually index your foreign keys as well, you can remove these
duplicates as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Brian S. Smith" <sa***@leapse.com> wrote in message
news:4a**************************@posting.google.c om...

Please help. I've been through the Access help, searched the Web, and
I can't seem to get a straight answer. As the Subject line suggests, I
want to run a fairly simple VB/Access Sub Function/Module that creates
relationships for my tables. The problem is that I need to provide for
some tables that may have > 32 relationships (which is apparently the
limit on Indexes that Access can support). How can I prevent Access
from automatically creating these indexes, AND still get referential
integrity, as viewable in my Relationships window. I started with
this, which works fine until the 32 index-limit is reached:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT [FKp_115]
FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

Then I read that this would work:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT NO INDEX
[FKp_115] FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

I tried the "NO INDEX" key phrase everywhere imaginable, as well as
with "As Database" using .Execute, still to no avail. Using DROP
obliterates the referential integrity altogether. I sincerely hope
SOMEONE knows what I can do, and hopefully it won't require a page of
code and importing or using all sorts of esoteric do-dads...what the
heck, I'll take any solution. HELP!!! Feel free to post and/or email
me directly. Thanks in advance, -Brian sa***@leapse.com

Nov 13 '05 #2
Perhaps you could tell us a little more about your database design.
The need for over 32 relationships for a single table suggests that perhaps
a different table structure could be appropriate.

HTH
- Turtle

"Brian S. Smith" <sa***@leapse.com> wrote in message
news:4a**************************@posting.google.c om...
Hi gang,

Please help. I've been through the Access help, searched the Web, and
I can't seem to get a straight answer. As the Subject line suggests, I
want to run a fairly simple VB/Access Sub Function/Module that creates
relationships for my tables. The problem is that I need to provide for
some tables that may have > 32 relationships (which is apparently the
limit on Indexes that Access can support). How can I prevent Access
from automatically creating these indexes, AND still get referential
integrity, as viewable in my Relationships window. I started with
this, which works fine until the 32 index-limit is reached:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT [FKp_115]
FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

Then I read that this would work:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT NO INDEX
[FKp_115] FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

I tried the "NO INDEX" key phrase everywhere imaginable, as well as
with "As Database" using .Execute, still to no avail. Using DROP
obliterates the referential integrity altogether. I sincerely hope
SOMEONE knows what I can do, and hopefully it won't require a page of
code and importing or using all sorts of esoteric do-dads...what the
heck, I'll take any solution. HELP!!! Feel free to post and/or email
me directly. Thanks in advance, -Brian sa***@leapse.com

Nov 13 '05 #3
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40***********************@freenews.iinet.net. au...
Hi Brian.

If we are talking about JET here (i.e. if your tables are in an Access
database), you will not be able to do that. JET must have a unique index in order to create a relationship with RI.

Your table may have some spurious indexes that you can dump. By default,
Access creates an index on any field that has a name ending in ID, Code,
Num, etc. (To avoid that: Tools | Options | Tables/Queries | Autoindex.)

I don't think this behaviour applies when you create constraints using DDL.
Nov 13 '05 #4
"Brian S. Smith" <sa***@leapse.com> wrote in message
news:4a**************************@posting.google.c om...
Hi gang,

Please help. I've been through the Access help, searched the Web, and
I can't seem to get a straight answer. As the Subject line suggests, I
want to run a fairly simple VB/Access Sub Function/Module that creates
relationships for my tables. The problem is that I need to provide for
some tables that may have > 32 relationships (which is apparently the
limit on Indexes that Access can support). How can I prevent Access
from automatically creating these indexes, AND still get referential
integrity, as viewable in my Relationships window. I started with
this, which works fine until the 32 index-limit is reached:


I think that Access does not create an index when you define a constraint
using DDL. Perhaps constraints themselves count towards the 32 index limit.

BTW, a table with 32 foreign keys often indicates a design problem, but you
may have a special case.
Nov 13 '05 #5
"John Winterbottom" <as******@hotmail.com> wrote:
BTW, a table with 32 foreign keys often indicates a design problem, but you
may have a special case.


And I have one of those special cases. An MDB with 150 tables with at least 30 or
40 joins to the Job table. So it's unlikely but possible.

We also print the relationships diagram on a 36" plotter. It's about as tall as it's
wide. I can fit one more layer of tables, maybe two at the bottom before I run out
of room.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 13 '05 #6
"Tony Toews" <tt****@telusplanet.net> wrote in message
news:3t********************************@4ax.com...
"John Winterbottom" <as******@hotmail.com> wrote:
BTW, a table with 32 foreign keys often indicates a design problem, but youmay have a special case.
And I have one of those special cases. An MDB with 150 tables with at

least 30 or 40 joins to the Job table. So it's unlikely but possible.

We also print the relationships diagram on a 36" plotter. It's about as tall as it's wide. I can fit one more layer of tables, maybe two at the bottom before I run out of room.

Oh, yes I know these cases do exist - that's why I add the proviso :) A
little more on this subject though - after some testing it seems that when
you create a FK constraint using a DDL script, an index is added to the
tables' DAO indexes collection, even though no index is visible through the
UI. Perhaps Jet creates in index to enforce the constraint. AFAIK this is
different behaviour to sql server, where a constraint and an index are two
separate things.
Nov 13 '05 #7
"John Winterbottom" <as******@hotmail.com> wrote:
Oh, yes I know these cases do exist - that's why I add the proviso :) A
little more on this subject though - after some testing it seems that when
you create a FK constraint using a DDL script, an index is added to the
tables' DAO indexes collection, even though no index is visible through the
UI. Perhaps Jet creates in index to enforce the constraint. AFAIK this is
different behaviour to sql server, where a constraint and an index are two
separate things.


Yup, Jet does the same thing if you create a relationship via the GUI and the DAO
relationships collection.

Tony

--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 13 '05 #8
Thank you all for your prompt responses! This is a great group.

Sounds like I'm SOL. Just to clear things up, though, the table and
its relationships are what is given to me in another form in another
application, so I know it is not an optimal design--and it really
isn't intended to be; it's more of a conceptual model.

But John, you have given me a glimmer of hope with your comment about
DDL. As you know, Access automatically creates indexes when you
specify a foregin key constraint. Could you give me some guidance on
how I can avoid this via DDL? Here's the example of what I'm using
agian:

strSQL = "ALTER TABLE Movement_Authority ADD CONSTRAINT [FKp_115]
FOREIGN KEY ([FKp_Limit]) REFERENCES Limit;
DoCmd.RunSQL strSQL

What is the syntax I can use to create a relationship WITHOUT an
index???

Thanks a whole bunch.

-Brian
"John Winterbottom" <as******@hotmail.com> wrote in message news:<2i************@uni-berlin.de>...
"Brian S. Smith" <sa***@leapse.com> wrote in message
news:4a**************************@posting.google.c om...
Hi gang,

Please help. I've been through the Access help, searched the Web, and
I can't seem to get a straight answer. As the Subject line suggests, I
want to run a fairly simple VB/Access Sub Function/Module that creates
relationships for my tables. The problem is that I need to provide for
some tables that may have > 32 relationships (which is apparently the
limit on Indexes that Access can support). How can I prevent Access
from automatically creating these indexes, AND still get referential
integrity, as viewable in my Relationships window. I started with
this, which works fine until the 32 index-limit is reached:


I think that Access does not create an index when you define a constraint
using DDL. Perhaps constraints themselves count towards the 32 index limit.

BTW, a table with 32 foreign keys often indicates a design problem, but you
may have a special case.

Nov 13 '05 #9

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

Similar topics

4
by: Thomas Jespersen | last post by:
Hello I want to create a MSI file programmatically. Do you know of any third party .NET component which can help me with that? I'm going to use it like a self extracting zip. So it is not...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
4
by: Melissa | last post by:
I have a frontend file named CustomerApp and backend file named CustomerData. CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer Database. Could someone help me with the code...
3
by: teedilo | last post by:
Our MS SQL (SQL Server 2000) DBA has database privileges locked down pretty tightly. We end users/developers do not have administrator privileges for most databases. That arrangement has worked...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
14
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
2
by: Wayne Deleer | last post by:
Hi All, I'm currently working on a project, and I've come to a part where I want to add data to a GridView. BUT, I want to do it programmatically, with alot of control over everything. In my...
0
by: Shootah | last post by:
Hi, I have succeeded in adding automated relationships with refference tables after importing an excel file created from a query to an Access database. However I have the following problem: ...
11
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.