views:

390

answers:

5

I am attempting to build a database for inventory control using a large number of tables and enforced relationships, and I just ran into the 32-relationship (index) limit for an Access table (using Access 2007).

Just to clarify: the problem isn't that the Employees table has 32 explicit indexes. Rather, the problem is the limitation on the number of times the Employee table can be referenced in FOREIGN KEY constraints. For example:

CREATE TABLE Employees (employee_number INTEGER NOT NULL UNIQUE)
;
CREATE TABLE Table01 (employee_number INTEGER NOT NULL REFERENCES Employees (employee_number))
;
CREATE TABLE Table02 (employee_number INTEGER NOT NULL REFERENCES Employees (employee_number))
;
CREATE TABLE Table03 (employee_number INTEGER NOT NULL REFERENCES Employees (employee_number))
;

...

CREATE TABLE Table30 (employee_number INTEGER NOT NULL REFERENCES Employees (employee_number))
;
CREATE TABLE Table31 (employee_number INTEGER NOT NULL REFERENCES Employees (employee_number))
;
CREATE TABLE Table32 (employee_number INTEGER NOT NULL REFERENCES Employees (employee_number))
;

An exception is thrown on the last line above, "Could not create index; too many indexes defined.

What options do I have to work around this limitation?

I've heard that creating a duplicate table with a 1:1 relationship is one method. I'm new to database design, so please correct me if I'm wrong; but given a table Employees with 31 indexes, I would create a table Employees2(with one field?) with a 1:1 relationship to Employees and relationships to this new table from any remaining relations in which EmployeeID is a foreign key. What's the best way to ensure the second table is populated alongside the first?

Is there another approach?

Based on the lack of information available, it seems this may be a rare problem with a properly-designed database, or the solution is common knowledge. Forgive the noob!

Update: Immediate consensus is that my design is borked or far too ambitious. This could very well be the case. However, I'd rather have a general design discussion within a separate question, so for the sake of argument, can someone answer this one? If the answer is simply "Don't ever do that" I'll have to accept it.

+2  A: 

It is hard for me to believe that an Employee table would need 32 indexes; if it actually does you should consider migrating to at least SQL Express.

Otávio Décio
or anything else that isn't Access
rmeador
I agree with ocdecio, having an employee table that requires 32 relationships seems strange, however we don't know your req's. +1 for migrating to SQLServer, I believe you can link an Access front end to the SqlServer backend (but have never tried it)
Nathan Koop
Agreed--Access isn't exactly my first choice. But supposing I'm stuck with it for now? I'd like to understand the options I have within this system so that I can make a fully-informed decision to migrate.
freestyletin
"Access isn't exactly my first choice" ... what would be, then?
Smandoli
@Smandoli SQL Server is obviously more robust and better-suited to large databases.I'm sure there are a number of better options out there, but the question still remains: how would I get around the limit in Access? See the update to my question. If it's not a valid question, I can live with that.
freestyletin
I would suggest that 32 indexes is more likely to represent a design error than to be a correct implementation, and failing to correct the design error and migrating to a database that supports more index is just going to exacerbate the problem in the original design.
David-W-Fenton
@rmeador: Platform bashing isn't going to solve this guy's problem.
JohnFx
A: 

Okay so, I've built a lot of applications and I have never needed 32 relationships for a single table.

Now, I could assume you're developing a super kick-ass application that blows everything I've ever written out of the water...

but you're using access.

... So instead I'm going to assume you're doing something wrong and ask, why do you need 32 relationships?

Spencer Ruport
This isn't an answer so I'm loathe to upvote it (yet). However the 32-rel is preposterous, and this database ain't gonna run. Other answers so far say "use a different database program," but this database ain't gonna run on those either.
Smandoli
A: 

I've run into this limitation a number of times with my apps. And I can assure the other posters that my apps are very well designed.

One problem is that Access creates indexes due to relationships and lookup fields that aren't viewable on the main index property box but they are accessible via DAO collections. These indexes are frequently duplicate indexes to indexes you have created as well.

I have a tool consisting of several forms you import into your BE MDB that allows you to remove the duplicate indexes. As I haven't yet made this available on my website please email me for it.

Tony Toews
Have you run into the problem because of the hidden and automatically-created indexes? That is, have you ever encountered it with only the indexes you intended to add?
David-W-Fenton
David, not sure I understand your question. Whenever I've encountered this problem there have been both indexes Access created behind the scenes and indexes I created. So I removed the indexes I had created which got me around the problem. Although in one particular app that wasn't enough.
Tony Toews
One advantage of using SQL DLL in ANSI-92 Query Mode is you can use the keywords NO INDEX in a FOREIGN KEY declaration to prevent the creation of the implicit index. Now that's converted you all into SQL DDL fanatics, right? ;)
onedaywhen
But why would you want to? Chances are exceedingly high that you would want an index on a foreign key for performance purposes.
Tony Toews
A few phrases and the tone of your comment comes across as sarcastic.
Tony Toews
If I were getting acquainted with MS Access via Stack Overflow, I'm afraid I'd conclude Access is snarky and easily offended.
Smandoli
@Tony: I'll try again. Why would you want to create no index? For all the usual reasons, with which I'm sure you are familiar (e.g. index selectivity), and so that you do not have to subsequently drop it. Why did the SQL Server team add the 'fast foreign keys' feature to the Jet 4.0 engine? AFAIK this is not publicly documented and I cannot speculate. More interestingly, why do Access MVPs not use the features added to the engine in the last decade? i.e. shouldn't MVPs at least be steering the engine feature set around to those that regular/power Access users would use?
onedaywhen
A: 

... I would create a table Employees2(with one field?) with a 1:1 relationship to Employees and relationships to this new table from any remaining relations in which EmployeeID is a foreign key.

That is workable. Presumably your main table might have an Autonumber field as the primary key, or you generate an index number. Your Employees2 table obviously must echo that.

What's the best way to ensure the second table is populated alongside the first?

That depends somewhat on how you are adding records. But in general, of course you must comply with the rules for integrity. This usually comes down to appending to tables in the correct order and ensuring each record is saved before trying to add a related record elsewhere.

Smandoli
Great, my main concern was that my approach to this problem was valid (misdirected or no). I should be able to set up a form to add new records to Employees and a copy of their corresponding ID to the second table.
freestyletin
Good. I trust it will go well. If you want to post on the basic table scheme ("How would you approach ...") and flesh out the details, I'd be very interested in what you get.
Smandoli
+1  A: 

I'd suggest just not defining all the relationships/indexes to implementing a 1:1 relationship to get around it. Neither solution is optimal, but the later is going to create a much higher maintenance burden and data anomaly potential.

I am not going to decry the design as quicky as some of the others, but it does have me intrigued. Could you list the fields of the employee table that are foreign keys? There is a good liklihood that some normalization is in order and maybe some of the smart people on SO could make some design suggestions to work around the issue.

JohnFx
I have this same interest in the scheme. I still think a fresh post would be appropriate
Smandoli