November 14, 2007 at 1:25 am
I want create new database
Option A
customer_id, int
process_year, smallint
process_month, tinyint
process_day, tinyint
a varhchar(20)
b varhchar(20)
c varhchar(20)
d varhchar(20)
with non_clustered index
customer_id, process_day, process_month, process_year
or
Option B
customer_id, int
process_date smalldatetime
a varhchar(20)
b varhchar(20)
c varhchar(20)
d varhchar(20)
with non clustered index
customer_id, process_date
I will search customer_id and process_date range,
which opition will you choose? A or B
November 15, 2007 at 11:15 pm
Hi
option b sould be my choice. u can have a index on the datetime column. Also if time part is important then its better to use datetime. Having said this there are situations where option A might eb usefull.
As always it depends..
"Keep Trying"
December 2, 2007 at 4:25 pm
Use Option B. There are functions to work with dates and you don't need to reinvent them. Too easy to make mistakes.
If you need to query on year or month often, you can use datepart (performance hit), but you could just store the year, month, or date separately for those times you need it.
If you give us more of a hint about what you're doing, we can help. Especially if you put it in the design forum.
December 2, 2007 at 4:45 pm
B
--Jeff Moden
Change is inevitable... Change for the better is not.
December 3, 2007 at 4:05 am
Jeff Moden (12/2/2007)
A
Why would you say that?
I'd say B. Dates should be stored in datetime columns, not seperated out. There are a couple of good reasons
There are some quite powerful datetime functions in SQL, that you'll struggle to use if the day, month and year are split and stored seperatly.
You don't save any space storing them seperatly, and you'll be spending CPU cycles turning them into dates for any form of manipulation or comparison.
If the parts are stored separatly and you don't have some carefully coded check constraints, you can get strange things like the 31st November, 29th Feb in a non-leap year and all such messes.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 3, 2007 at 4:37 am
I would also select option B. If you ever need to get more granular with the date and need to see the time of day this won't be available with option A.
December 3, 2007 at 7:39 am
Sorry, edited my post as well. I think B (using datetime) makes more sense. Include the other int columns if it helps performance.
December 3, 2007 at 7:45 am
I'll go for option B..., makes sense querying a date directly rather than concatenating integers to make a date then query it!!!!
--Ramesh
December 4, 2007 at 6:37 am
GilaMonster (12/3/2007)
Jeff Moden (12/2/2007)
AWhy would you say that?
I'd say B. Dates should be stored in datetime columns, not seperated out. There are a couple of good reasons
There are some quite powerful datetime functions in SQL, that you'll struggle to use if the day, month and year are split and stored seperatly.
You don't save any space storing them seperatly, and you'll be spending CPU cycles turning them into dates for any form of manipulation or comparison.
If the parts are stored separatly and you don't have some carefully coded check constraints, you can get strange things like the 31st November, 29th Feb in a non-leap year and all such messes.
Oh bugger... mostly because I didn't have enough coffee when I read that... I was thinking that option "A" was the worst thing you could do, went to type "B" and, apparently, typed the wrong letter. Sorry folks...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply