views:

910

answers:

5

A normalized table should have less number columns and can have reference fields as much as possible. Is it right approach? Is there any relationship between number of columns and a good normalization process?

+7  A: 

You should follow the normalization principles rather than be concerned with the sheer number of columns in a table. The business requirements will drive the entities, their attributes and their relationship and no absolute number is the "correct" one.

Otávio Décio
+7  A: 

Is there any relationship between number of columns and a good normalization process?

In short, no. A 3NF normalized table will have as many columns as it needs, provided that

data within the table is dependent on the key, the whole key, and nothing but the key (so help me Codd).

There are situations where (some) denormalization may actually improve performance and the only real measure of when this should be done is to test it.

Russ Cam
+1 for the phrase: "data within the table is dependent on the key, the whole key, and nothing but the key (so help me Codd)." What a great line...I am astonished I've never heard it before. Did you make this up or do you have a source?
Mark Brittingham
Russ Cam
Agreed, awesome phrase, +1.
RedFilter
I'm pretty sure the phrase is much older than that. I had a database course at business school (yes, it was a strange course), and the teacher would use that phrase all the time. This was in 1995.
Jess
@LuckyLindy - The phrase is probably older than me, but the first time I heard it was a while ago, I believe in SQL Server 2005 bible (although I'm starting to doubt that now. I've read too many SQL/DB books to keep track, to be honest) :)
Russ Cam
+2  A: 

While I agree with @ocdecio, I would also observe that a database that is normalized will generally have fewer columns per table and more tables than one that is not, given the same data storage requirements. Similar to code smells a database smell would be relatively few tables given a reasonably large application. This would be a hint that perhaps your data is not in normal form. Applying normalization rules, where appropriate, would alleviate this "smell".

tvanfosson
That is true; what I wanted to point out is that if you follow the roles you might not see the denormalized version of your database. And it is true, the feeling of "too many columns" is a good smell indicator of bad normalization.
Otávio Décio
I agree that it may be a "reasonable" indicator, but nothing more. I just had a look at some of the tables in the Cisco IPCC database schema and there are 90+ columns in some tables. Granted, there are a number of persisted computed columns, but I think the point that I'm trying to make is...
Russ Cam
that the nature of the data will dictate the number of columns in tables (in my example, VoIP telephony platform). BTW, The Cisco IPCC database schema is reasonably normalized.
Russ Cam
I agree that, in two databases targeting the same problem, the one that is properly normalized will have fewer columns per table than one that is not. I'd almost hate to tell this to newbies, though, as they'll just make tables w/ fewer columns, point and say: "look, normalized!" *slaps forehead*
Mark Brittingham
+2  A: 

Here is an approach you can use if you feel your table has too many fields. Example:-

CREATE TABLE Person
    Person_ID int not null primary key,
    Forename nvarchar(50) not null,
    Surname nvarchar(50) not null,
    Username varchar(20) null,
    PasswordHash varchar(50) null

This table represents people but clearly not all people need be users hence the Username and PasswordHash fields are nullable. However its possible that there will be 1 or 2 orders of magnitude more people than there are users.

In such case we could create a User table to hold the Username and PasswordHash fields with a one-to-one relationship to the Person table.

You can generalise this approach by looking for sets of nullable fields that either null together of have values together and significantly likely to be null. This indicates that there is another table you could extract.

AnthonyWJones
A: 

Each column must have a direct and exclusive relationship to the primary key. If you have an attribute-heavy item that there is only so much you can do to simplify the model. Any attempt to split into multiple tables will be counter-productive and pointless.

paul