views:

159

answers:

5

If my table has a huge number of columns (over 80) should I split it into several tables with a 1-to-1 relationship or just keep it as it is? Why? My main concern is performance.

PS - my table is already in 3rd normal form.

PS2 - I am using MS Sql Server 2008.

PS3 - I do not need to access all table data at once, but rather have 3 different categories of data within that table, which I access separately. It is something like: member preferences, member account, member profile.

+4  A: 

80 columns really isn't that many...

I wouldn't worry about it from a performance standpoint. Having a single table (if you're typically using all of the data in your standard operations) will probably outperform multiple tables with 1-1 relationships, especially if you're indexing appropriately.

I would worry about this (potentially) from a maintenance standpoint, though. The more columns of data in a single table, the less understandable the role of that table in your grand scheme becomes. Also, if you're typically only using a small subset of the data, and all 80 columns are not always required, splitting into 2+ tables might help performance.

Reed Copsey
A: 

Depends what those columns are. If you've got hard coded duplicated fields like Colour1, Colour2, Colour3, then these are candidates for child tables. My general rule of thumb is if there's more than one field of the same type (Colour), then you might as well code for N of them, not a fixed number.

Rob.

Rob Nicholson
Nope. I do not have such columns. Third Normal Form is respected.
niaher
A: 

1-1 may be easier, if you have say Member_Info; Member_Pref; Member_Profile. Having too many columns can make it run if you want lots of varchar(255) as you may go over the rowsize limit, and it just makes it too confusing.

Just make sure you have the correct forgein key constraints and suchwhat, so there's always 1 row in each table with the same member_id

glasnt
+3  A: 

Re the performance question - it depends. The larger a row is, the less rows can be read from disk in one read. If you have a lot of rows, and you want to be able to read the core information from the table very quickly, then it may be worth splitting it into two tables - one with small rows with only the core info that can be read quickly, and an extra table containing all the info you rarely use that you can lookup when needed.

Tim Haines
I haven't thought about it from this perspective and I totally agree with your argument. However in my case I will always only retrieve a single row specified by primary key.
niaher
If you're only ever retrieving a single row at once, then you probably won't have performance issues with it. You may want to split it for non performance reasons though. i.e. if often many of the fields are unused, you might be able to save a lot of disk space by moving them out of the table into another, and only creating rows when you have info for those columns.
Tim Haines
+2  A: 

Taking another tack, from a maintenance & testing point of view, if as you say you have 3 distinct groups of data in the one table albeit all with the same unique id (e.g. member_id) it might make sense to split it out into separate tables.

If you need to add fields to say your profile details section of the members info table, do you really want to run the risk of having to re-test the preferences & account details elements of your app as well to ensure no knock on impacts.

Also for audit trail purposes if you want to track the last user ID/Timestamp to change a members data. If the admin app allows Preferences/Account Details/Profile Details to be updated separately then it makes sense to have them in separate tables to more easily track updates.

Not quite a SQL/Performance answer but maybe something to look at from a DB & App design pov

MadMurf