473,837 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do I need keys/indexes for a 3column table?


Folks,

My internet access is intermitent until I get my own connection inside
the next ten days - I say this so that I can thank in advance who ever
gives a few seconds to read/answer my query...

Basically - I have three columns in my table... product name hash,
product tax code and a unique numeric record id.

A product can contain one or more taxes hence this table is a
relationship table that will

1) allow me to search all taxes for a single product or
2) all products that are tied to a specific tax

and I will use the unique numeric id if I want to delete one or more of
the taxes tied to a single product.

My question:
Should I have keys/indexes for each of the columns? Is it one of those
questions that is best answered with six of one and half a dozen of the
other? I believe in this case because the table is so small and likely
only to contain a couple of thousand records at maximum, it would be
unhealthy to have indexes as maintaining them would create a bit of an
overhead. What though, if the table were to contain a larger amount of
records (say, in the millions) but retain the same number of columns -
what would be the best advice in this case?

I'd be grateful for a reply to the newsgroup (so all can learn) and I'll
find somewhere to read the reply over the next days.

Much appreciated,
Randell D.
Aug 22 '05 #1
3 1704
Randell D. wrote:
Should I have keys/indexes for each of the columns?
If you want to search data from the table and use certain column to
identify which rows should be returned, then that column should have
index, unless you think that having index causes too slow inserts or
takes too much hard drive space. In normal situations slow inserts and
hard drive space are not issues.

Also, normally searches in one table are quite fast and last under 0
seconds with less than 10 000 rows. Search in multiple tables with joins
can be hours or 0 seconds, depending on whether you have indexes or not
on the columns you are using in search.

According to your specifications: 1) allow me to search all taxes for a single product or
2) all products that are tied to a specific tax


You need to have two indexes in that table. One for product id and one
for tax id.
Aug 22 '05 #2
>Basically - I have three columns in my table... product name hash,
product tax code and a unique numeric record id.
If you want the database to enforce uniqueness on the record id
(e.g. it's an auto_increment) , you need a unique index on that
column.

Is (product name hash, product tax code) unique? Although a product
can have more than one tax and a tax can have more than one product,
can the SAME product have the SAME tax twice? Do you need to enforce
this? If so, you need a unique index on either (product name hash,
product tax code) or (product tax code, product name hash).
A product can contain one or more taxes hence this table is a
relationship table that will

1) allow me to search all taxes for a single product or
2) all products that are tied to a specific tax
What is the relative frequency of these types of queries?
You will still be able to do both, but if you only need one
type a few times during annual tax preparation, it may not be
worth having an index for only that.
and I will use the unique numeric id if I want to delete one or more of
the taxes tied to a single product.

My question:
Should I have keys/indexes for each of the columns? Is it one of those
questions that is best answered with six of one and half a dozen of the
other? I believe in this case because the table is so small and likely
only to contain a couple of thousand records at maximum, it would be
unhealthy to have indexes as maintaining them would create a bit of an
overhead. What though, if the table were to contain a larger amount of
records (say, in the millions) but retain the same number of columns -
what would be the best advice in this case?


Indexes take time to maintain WHEN YOU MAKE CHANGES (or when you
add or delete them). How often will you be changing the table,
compared to how often you make queries? Is disk space a big issue?
You might want to try queries with and without the indexes (You can
add and delete indexes with ALTER TABLE) and see if it makes enough
difference to matter. Certainly for a million records it would
save a lot in disk I/O.

If you aren't going to make a lot of changes to the table, go for the
indexes. If the speed of the changes is not a big deal, but the speed
of the lookups is (someone's waiting on the phone for a quote),
go for the indexes. If changes are about 10 times as frequent as lookups,
you may want only the index on the unique record id.

Gordon L. Burditt
Aug 22 '05 #3
Gordon Burditt wrote:
Basically - I have three columns in my table... product name hash,
product tax code and a unique numeric record id.

If you want the database to enforce uniqueness on the record id
(e.g. it's an auto_increment) , you need a unique index on that
column.

Is (product name hash, product tax code) unique? Although a product
can have more than one tax and a tax can have more than one product,
can the SAME product have the SAME tax twice? Do you need to enforce
this? If so, you need a unique index on either (product name hash,
product tax code) or (product tax code, product name hash).

A product can contain one or more taxes hence this table is a
relationshi p table that will

1) allow me to search all taxes for a single product or
2) all products that are tied to a specific tax

What is the relative frequency of these types of queries?
You will still be able to do both, but if you only need one
type a few times during annual tax preparation, it may not be
worth having an index for only that.

and I will use the unique numeric id if I want to delete one or more of
the taxes tied to a single product.

My question:
Should I have keys/indexes for each of the columns? Is it one of those
questions that is best answered with six of one and half a dozen of the
other? I believe in this case because the table is so small and likely
only to contain a couple of thousand records at maximum, it would be
unhealthy to have indexes as maintaining them would create a bit of an
overhead. What though, if the table were to contain a larger amount of
records (say, in the millions) but retain the same number of columns -
what would be the best advice in this case?

Indexes take time to maintain WHEN YOU MAKE CHANGES (or when you
add or delete them). How often will you be changing the table,
compared to how often you make queries? Is disk space a big issue?
You might want to try queries with and without the indexes (You can
add and delete indexes with ALTER TABLE) and see if it makes enough
difference to matter. Certainly for a million records it would
save a lot in disk I/O.

If you aren't going to make a lot of changes to the table, go for the
indexes. If the speed of the changes is not a big deal, but the speed
of the lookups is (someone's waiting on the phone for a quote),
go for the indexes. If changes are about 10 times as frequent as lookups,
you may want only the index on the unique record id.

Gordon L. Burditt

Thanks for those comments - it gave food for thought and I think I will
use the indexes since there will be fewer changes and more reads using
one column to lookup the other.

Thanks!
Randell D.
Aug 23 '05 #4

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

Similar topics

5
7134
by: Randell D. | last post by:
Can anyone tell me what the difference is between keys and indexes? Much appreciated, randelld
2
1221
by: Randell D. | last post by:
Folks, I have a table that has five columns in it - It collates references to records in five other tables. I understand that an index/key can help improve performance when searching - however I also believe too many keys can hamper performance since table updates also mean updateing the indexes. Thus - Since all five columns in my table can be used individually for specific searches, would I be better off not having keys - Since the
7
6500
by: Aleem | last post by:
I need help in writing a stored procedure on SQL Server 2000. Basically the stored procedure's primary task is to generate invoice records and insert the records in a invoice table. In order to generate the invoice records, I have an initial table which are basically Day Records. The task that I would like to complete is to select all records from that initial table and I guess put them into a temp table. Now that i have my temp table, I...
1
3528
by: Woody Rao | last post by:
I'm trying to drop all indexes and primary keys so that i can rebuild them (from a script created from same database on another server). when i go to the 'generate sql scripts', it has the ability to drop or generate all tables. it also has the ability to generate all keys only. but i cant find a way to drop all of these keys... any ideas?
1
3010
by: Vinodh Kumar P | last post by:
I understand the number of foreign keys allowed is restricted by the DBMS I use. In a general relational schema design perspective how many foreign keys a table shall have? If I have large number of foreign keys what anamolies it will lead to? Is this crucial to identify all the foriegn key relationships for a table? Vinodh
6
2813
by: Brendan Jurd | last post by:
Hi all, I read on the manual page for Inheritance that: "A limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single tables, not to their inheritance children. Thus, in the above example, specifying that another table's column REFERENCES cities(name) would allow the other table to contain city names but not capital names. This deficiency will probably be fixed...
115
6291
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can I use them as primary keys or should I define an autonum primary key? One table has information about the 50 states in the US. The table looks like this:
2
3513
by: lfhenry | last post by:
Hi All, I am about to make some changes to a process we have. The new process will have a new table who's job it is to store temporarily data such as customer, clerkno,productno, storeno , amount, time. On a new request from a front-end i will select against the primary keys to ensure no other request for the same data has been made. This is then sent to a backend system asynchronously if there is no match. I will otherwise send a...
16
4863
by: Okonita via DBMonster.com | last post by:
Hi all, I am comming along with all this Linus/DB2/scripting business...I am no longer scared of it!! (LOL). But, I need to create a .ksh script that does a REORGCHK and output only tables recommended for reorg. My goal is to reorgchk and run reorgs based on entries in this reorg file as shown in the example below. I have tried my hand at the following failing script and hope that gurus here can throw me a lifeline of examples on how to...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10272
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7001
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3124
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.