Yes, of course. A secondary key is just a unique key (index), which is not the primary key.Can you have a secondary key in access? Or can you just have 2 Key fields?
In what way is that related to secondary keys? - You might be on a path to unnecessary dependencies.Thinking of breaking up a table into different, smaller tables.
Yes, of course. A secondary key is just a unique key (index), which is not the primary key.
In what way is that related to secondary keys? - You might be on a path to unnecessary dependencies.
Is there a way to define a data field as an index? I have a table that is getting wide and I am considering breaking it up, Just thinkingThere are many situations where you would want to use an autonumber as the primary key and a different field as a unique index to prevent duplicates. For example, when you interface with a different application, that application might have a unique PK but since you do not control it, it is generally better for you to use an autonumber as the PK and instead use the other system's unique identifier as a unique index to prevent duplicates. One example might be a driver's license. Since they are issued by states, if you have employees from multiple states, you don't want to mix the IDs for multiple states into one field because there could be duplicates or conflicts in format. But, you want to define them as unique to avoid errors so you might make a compound unique index with StateID + DriversLicense. Also, combos will not work correctly unless you have a single unique identifier so the path of least resistance is to use autonumbers as your primary keys but define unique indexes to support business rules.
Of course. In the properties list of every column of a table in design view there is a property "Indexed". Set this property to "Yes (No Duplicates)" and you'll get a unique index (key) on that column. For more complex (e.g. multi-colum) indexes turn to the "Indexes" button in the ribbon, as @The_Doc_Man suggested.Is there a way to define a data field as an index? I have a table that is getting wide and I am considering breaking it up, Just thinking
Thanks for the information. Will read.Mechanically speaking, get onto the table's Field Definitions and look above the field grid. There should be a button in the ribbon for indexes.
HOWEVER, be careful about breaking up a table just because "it is getting wide." If that "breaking up" includes normalizing the data, then go for it. But if your goal was to have a 1-1 relationship between the two table parts... DON'T DO IT. Having a two-table 1-1 relationship is almost a guarantee of a headache.
If you can normalize your data as a way to reduce the width of the table, that is the correct way to approach the problem. If you table looks more like a spreadsheet (and is more often treated that way), you may have a serious structural problem that will eventually eat your lunch for you.
If you are not familiar with normalization, then it is time and past time to start reading. In this forum, just search for NORMALIZATION because this is a database forum. However, doing a web search, you must look for DATABASE NORMALIZATION because the word normalization also appears in politics, mathematics, chemistry, biochemistry, psychiatry, and a few other diverse topics. If you go the web route, I advise you to start with articles from the .EDU domain because articles from the .COM domain often want to sell you something. However, after a couple of good articles, the .COM sites are fair game and actually often DO have decent articles to contribute.
Thanks for the lesson. Will keep it as a referenceI've spent 50+ years designing and developing business applications using relational databases and probably used 1-1 relationships 3 times. They are EXTREMELY rare and NEVER created because your table is too wide. As the others have suggested, if your table is too wide, it is almost certainly in need of normalization. Look for sets of fields with prefixes or suffixes, especially numeric ones. Sometimes the repeating groups are harder to spot because the names are all different. How about, electric, gas, oil, water, snow shovelling, lawn mowing, cable, etc. Can you identify the pattern even though the names are all different?
But just to be complete, in a 1-1 relationship, one of the tables is the "master". It is the one with the autonumber PK and it is always inserted first. The "child" table uses a long integer as it's PK and that same field is also the FK to the "master".
On indexes:
There are two ways to create indexes. One method is used for single field indexes and the second is used for multi-field indexes.
Open the table in design view
1. Use the Index property for single field indexes.
2. Open the indexes dialog to create multi-field indexes. Give the first row a name and set the property to unique if necessary. Then for each subsequent row, leave the name blank. Access supports a MAXIMUM of 10 fields in an index. SQL Server allowsView attachment 103809 32 I think.