Wednesday, March 7, 2012

datetime

Hello,
I have a table with a colume named orderTime.
Because of the size of the DB, I need to make sure all the data is
stream lined. This means that if I only need the time, I need to just
store the time. Unfortunately, datetime stores 1900-01-01 as a data
with the time which is a string from a VB app.
Anyway to insert just the time? I could change the column to a string,
but I rather not do that because I'm not sure if I can order by time
properly latter.> Anyway to insert just the time?
No, SQL Server does not have a date only or time only datatype. But can't
you just always ignore 1900-01-01?
Some workarounds here, but they're not pretty.
http://www.aspfaq.com/2206
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/|||> No, SQL Server does not have a date only or time only datatype. But can't
> you just always ignore 1900-01-01?
> Some workarounds here, but they're not pretty.
> http://www.aspfaq.com/2206
Aaron,
Thanks. Yes, I can ignore them. The issue though is that because the
sheer amount of data I'm storing, I need to only insert data that is
needed. I guess I will just have to work around this. Thanks.|||> Thanks. Yes, I can ignore them. The issue though is that because the
> sheer amount of data I'm storing, I need to only insert data that is
> needed.
? If you store a date in a DATETIME or SMALLDATETIME, regardless if you
include all information, it still occupies 4 or 8 bytes respectively. So
"not inserting" the portion you don't need is not going to save you any
space.|||I don't loose any accuracy if I were to store that time as a char(8) and
then just do a CAST?
Which will take up less space?
I found this in Books Online,
When the collation code page uses double-byte characters, the storage
size is still n bytes. Depending on the character string, the storage
size of n bytes may be less than n characters.
Doesn't seem to give a definitive answer.|||SMALLDATETIME (4 bytes) will take up less space than a CHAR(8) (8 bytes).
Plus, you lose effectiveness of indexes and have to convert for every single
query.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Won Lee" <noemail@.nospam.com> wrote in message
news:#CfX$vIAEHA.2480@.TK2MSFTNGP12.phx.gbl...
> I don't loose any accuracy if I were to store that time as a char(8) and
> then just do a CAST?
> Which will take up less space?
> I found this in Books Online,
> When the collation code page uses double-byte characters, the storage
> size is still n bytes. Depending on the character string, the storage
> size of n bytes may be less than n characters.
>
> Doesn't seem to give a definitive answer.
>

No comments:

Post a Comment