tags:

views:

333

answers:

7

Which one do you prefer to store text in your database? The original casing of the data, or some kind of normalization. Also, should I enforce this with triggers? or should I preprocess input data with client code?

I ask you, because I'm not sure about if there is any difference, besides additional processing time to display data (capitalization of names, for example).

+1  A: 

I wouldn't worry about it, just format it how you need it to be used on output.

Unkwntech
+7  A: 

Store in original case, unless there is a reason to do otherwise. The time spent to upper or lower case the data is likely very small, and you never know when you'll want the real, original data back in the future.

tloach
+1  A: 

If you need to do lots of text field searches (strcol = "aBc"), you could consider normalizing. In some db systems like postgres, indexes aren't used with the ILIKE operator, although the text search specific indexes probably handle this better.

Dana the Sane
+2  A: 
  1. In the absence of a compelling need to have your data changed, don't change your data.
  2. In the absence of a compelling reason to have your database indices case sensitive, use case insensitive in your database.
  3. Spend time worrying about what a user sees and wants. This will guide you to your answer.
MattK
+4  A: 

It obviously depends on what you'll need to do with the data later.

But if you're asking because you're interested in speeding up lookups later (e.g. searching by name, city, etc.), you may want to create different indexes, so that those would be used instead for the lookups:

create table case_test (
  id integer,
  name varchar2(30));

create index ucasename on case_test(upper(name));

A query like this sample would use the case-insensitive index for selection criteria but return the name with casing as input originally:

select * from case_test where upper(name) like 'TUCK%';
BQ
A: 

Slightly off topic but... NEVER trust client side formatting of ANYTHING.

Chris Nava
When a user enters his name, trust that he knows better than you how it's supposed to be cased. When your database says "MACDONALD" you'll never know if he meant "MacDonald," "Macdonald," or "Mac Donald" unless you trust his input. You can't recover this info if you don't store it as is.
BQ
+1  A: 

Store in the actual case the user entered.

As a user, if i like my name as cHriS, I enter it that way and I like it that way. I don't like the application change it just for some technical reasons

If you want to optimize search, use separate indexes, don't change the data.

Nivas