Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

Data Type and Length Expand / Collapse
Author
Message
Posted Saturday, August 7, 2010 1:00 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, June 19, 2014 6:51 AM
Points: 1,264, Visits: 723
Comments posted to this topic are about the item Data Type and Length
Post #965579
Posted Saturday, August 7, 2010 1:04 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, June 26, 2014 5:34 AM
Points: 897, Visits: 1,486
Thanks for question. I just lost one point.

Now why in Heavens would there be two different behaviours for the same datatype?
Just to confuse people? Or is there a technical explanation for that?


Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2
Post #965580
Posted Saturday, August 7, 2010 8:11 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, July 10, 2014 12:49 PM
Points: 1,676, Visits: 1,754
codebyo (8/7/2010)
Now why in Heavens would there be two different behaviours for the same datatype?
Just to confuse people? Or is there a technical explanation for that?


This is a very good question, I really like it.

I think that this data type size behaviour is great. Since there is no way in SQL Server to punish the disobedient by, say, 12 lashes they deserve, this difference is actually a good way to teach them to never omit the size when declaring / converting variables. On the top of the 1 / 30 issue, there is another interesting twist to it: both ADODB and ADO.NET default the size of the varchar type procedure parameter to 50 if the size is not specified. The bottom line is that forgetting to specify the size is evil and should be avoided.

As far as a technical explanation is concerned, I believe that because the size is required, default values were provided by the parser team, and it probably just so happened that the declaration and conversion were written by different developers, that is all.

Oleg
Post #965616
Posted Saturday, August 7, 2010 10:59 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
Great question thanks!

This is a very good topic to cover, as I know a lot of developers don't understand the importance of specifying the size. (Good old VB "String" type.)
Post #965627
Posted Saturday, August 7, 2010 11:08 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, June 26, 2014 5:34 AM
Points: 897, Visits: 1,486
Oleg Netchaev (8/7/2010)
I think that this data type size behaviour is great. Since there is no way in SQL Server to punish the disobedient by, say, 12 lashes they deserve, this difference is actually a good way to teach them to never omit the size when declaring / converting variables. On the top of the 1 / 30 issue, there is another interesting twist to it: both ADODB and ADO.NET default the size of the varchar type procedure parameter to 50 if the size is not specified. The bottom line is that forgetting to specify the size is evil and should be avoided.

As far as a technical explanation is concerned, I believe that because the size is required, default values were provided by the parser team, and it probably just so happened that the declaration and conversion were written by different developers, that is all.

Oleg


You're right. Trusting default behaviours should be avoided at all costs.
But 12 lashes is too soft.


Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2
Post #965628
Posted Sunday, August 8, 2010 10:51 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:48 PM
Points: 21,229, Visits: 14,939
Great question. As the others have said, this underlines the necessity of specifying the size of the datatype.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #965722
Posted Monday, August 9, 2010 12:17 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 14, 2014 4:48 AM
Points: 2,834, Visits: 3,950
30 is for char or varchar ?

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #965737
Posted Monday, August 9, 2010 12:59 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:22 PM
Points: 5,925, Visits: 8,174
Good question! When I first saw it, I thought there would be a very high percentage of correct answers since the confusing default lengths for character strings have already been covered in a few recent QotD's. But the results say that at this time, only 53% of the respondents have given the right answer, so there is obviously still a lot of need to keep driving this point home. Good job, magasvs!


Bhuvnesh (8/9/2010)
30 is for char or varchar ?

Both, when used without length in a CONVERT() function call.
In a DECLARE, both char and varchar default to a length of 1.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #965746
Posted Monday, August 9, 2010 2:24 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Saturday, October 19, 2013 12:40 PM
Points: 361, Visits: 508
Good question!
Hugo Kornelis (8/9/2010)
...I thought there would be a very high percentage of correct answers since the confusing default lengths for character strings have already been covered in a few recent QotD's.

I guess people don't go through discussions. (July, 19th QotD only asked for the implicit length of variable declaration while the CONVERT behavior was mentioned and explained in the discussion that followed.)

Regards,

Hrvoje


Hrvoje Piasevoli
Post #965768
Posted Monday, August 9, 2010 3:54 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 3:12 AM
Points: 1,610, Visits: 5,482
Completely forgot about the CONVERT when answering this, but probably would have got it wrong even if I'd taken it into account...didn't know about this default length behaviour!
Post #965803
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse