views:

83

answers:

5

Hi.

In the project where I work I saw this structure in database, and I ask to all of you, what a hell of modeling is this?

TableX
Columns: isMonday, BeginingHourMonday, EndHourMonday, isTuesday, BeginingHourTuesday, EndHourTuesday and so on...

Is this no-sql? I did not asked to the personn who created becaus I'm ashamed :$

Bye.

+1  A: 

This is called a calendar table.

It is a very common and incredibly useful approach to dealing with and solving a lot of date and time related queries. It allows you to search, sort, group, or otherwise mine for data in interesting and clever ways.

Brian Gideon
+1  A: 

this is totally de-normalized data. no-sql kind of. i just wonder why month is not included. it could increase the de-normalization-factor.

iamgopal
+1  A: 

@Brian Gideon is right. So is @iamgopal. And I am too, when I say "it depends on the nature of the data being modeled and stored in the database".

If it is a list of days with certain attributes/properties for each day, then yes, I would call it denormalized -- and 9 times out of 10 (or more) this will probably be the case. (I recall a database with 13 columns, one for each month in the year and one for total, and at the end of the year the user added 13 more columns for the next year. "Mr. Database", we called him.)

If this is a description of, say, work hours within a week, where each and every time the data is queried you always require the information for each day in the week, then the row would represent one "unit" of data (each column dependant upon the primary key of the table and all that), and it would be counter-productive to split the data into smaller pieces.

And, of course, it might be a combination of the two -- data that was initially normalized down to one row per day, and then intentionally denormalized for performance reasons. Perhaps 9 times out of 10 they do need a weeks' worth of information, and analysis showed massive performance gains by concatenating that data into one row?

As it is, without further information on use and rational I'm siding with @iamgopal, and upvoting him.

Philip Kelley
A: 

Looks like a structure of a timesheet for a given week.
If normalized, it might look like

columns: day, startHour, endHour
When this is converted to a pivot table in excel, you will have a timesheet kind of a structure, which is good for input screens/views (as against creating a view with normalized structure).

shahkalpesh
A: 

Looking to that table. I don't see any good reason to do that, even for a performance reason.

Lets see, if I change the isMonday, isTuesday, etc to ID_Day I still get the same speed and logic. And if I change the BeginingHourMonday to StartHour and the EndHourMonday to EndHour, I still get the same effect.

I still have the day of week and the start and end time and that is the basically idea I get from the table struture. Maybe there is something I'm not seeing.

Regards

Bruno Costa