Simple clear advice in plain English

Hands on: Relationships in databases

We explain some of the basics of creating a database and planning relationships

caSE SEnsitIve joins
Joins, as described above, are case insensitive. Sara Athwal emailed with a problem that can only be solved with a case-sensitive join. She has written an Access database for her company and has a product table.

Each product in her company has a unique identifier made up of characters and numbers. As she says, these are completely unreadable (like Df3dD) because they are machine generated. The machine in question is a Unix-based system and Sara was horrified to discover, after she had built the database, that DF3dD was being used to signify a different product from Df3dD and Df3dd - in other words, it is case sensitive.

Her question is simple: “How can I perform a case-sensitive join?” It’s an interesting question with at least three answers - or one solution and two answers.

Solution 1
One solution is: “Are you sure you want to do that?” An alternative is to keep the machine-generated value in the table but not use it as the primary key. Instead, assign another unique number (possibly using an autonumber field) to each product and use that number as the primary key. This is potentially easier and may be faster when you perform the joins.

While this may be a solution, it doesn’t answer the question I was asked and you may find a case one day where a case-sensitive join is essential, so let’s look for active solutions.

Solution 2
Access doesn’t support case-sensitive joins without a bit of creative table-building, which relies on a more or less undocumented feature. When you’re shown the list of available field types when you’re creating a table, the Binary type does not figure. Nevertheless, it’s there and is used by some of Access’ internal system tables.

You can use it as you’d use the Text field type and it will behave as a Text field, except when used with any of the comparison operations (such as making joins and sorting or indexing fields). In these cases it uses the ASCII code value equivalent to the field contents and uses that for joining, sorting and indexing. There are different ASCII codes for each character in both cases (‘A’ is 65 and ‘a’ is 97) and this is how the Binary field can act in a case-sensitive fashion.

The Binary type isn’t on offer during the normal table-building process so we have to be a little sneaky in order to create a table with a binary field and use raw SQL. As part of its data definition language, SQL has a command called CREATE TABLE that does exactly what the name suggests. So if we run the following SQL:

CREATE TABLE PENGUIN (MyField binary (30))

it will create a table called ‘Penguin’ with a field called ‘MyField’ that is of type binary and able to accept up to 30 characters. How do we run this SQL?

Article tags

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

Create a shortcut to switch between power schemes illustration

Switch between several power schemes with a click of the mouse

Do you want to save battery or mains power? Find out how to switch between power management settings with a nothing more complicated than a double-click

Customise Notifications screenshot

Why has the Safely Remove Hardware icon disappeared?

Windows XP is hiding icons, but you can override this action

Edit Windows' right-click menus

How to add to and customise the right-click menus in Windows

If you right-click your mouse, a menu of extra options pops up. If you want to add extra choices to this, then Filerfrog makes it easy to customise your Windows list

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Samsung RV520-A07

£359.98- Buy it now

img

Acer Aspire 5750G (LX.RXP02.019)

£399.99- Buy it now

img

Apple MacBook Pro (MD313B/A)

£904.37- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Restore point

A Windows backup of system files and settings.

Great shopping deals from Computeractive