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 «««12345»»

Strings and Defaults Expand / Collapse
Author
Message
Posted Thursday, January 26, 2012 2:23 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 4:56 PM
Points: 8,271, Visits: 8,717
nice question.

Evey time I recall that default varchar length is 1 for declare but 30 for cast I feel sick and resolve never to use varchar without specifying the length.


Tom
Post #1242471
Posted Friday, January 27, 2012 12:46 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 1:31 PM
Points: 744, Visits: 1,124
I knew that second variable would hold all 50 characters just didn't realize that case as varchar without a length would default to 30. Makes sense. I should have realized that.
Post #1243110
Posted Wednesday, February 01, 2012 1:33 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 01, 2014 1:34 AM
Points: 1,950, Visits: 817
I want to side with those who find this inconsistency as unacceptable. I can live with defaults but in this case there are 2, 1 and 30. There should be one default or every varchar should have to specify a length. Maybe a Server or Database option.

It was a good question but you shouldn't have to know these arcane default values
Post #1244901
Posted Wednesday, February 01, 2012 2:35 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, February 17, 2014 9:44 AM
Points: 127, Visits: 105
Good Question, Thanks Gail.
Post #1244926
Posted Wednesday, February 01, 2012 6:01 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:42 PM
Points: 41,516, Visits: 34,431
David Conn (2/1/2012)
It was a good question but you shouldn't have to know these arcane default values


Personally my opinion is that you shouldn't have to know the defaults because you never ever declare varchar/char/nvarchar/nchar/binary/varbinary/etc without specifying a length.

I would personally like to see declaring one of those data types without specifying a length deprecated. Won't happen though.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1245012
Posted Wednesday, February 01, 2012 7:53 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 4:56 PM
Points: 8,271, Visits: 8,717
GilaMonster (2/1/2012)
David Conn (2/1/2012)
It was a good question but you shouldn't have to know these arcane default values


Personally my opinion is that you shouldn't have to know the defaults because you never ever declare varchar/char/nvarchar/nchar/binary/varbinary/etc without specifying a length.

I would personally like to see declaring one of those data types without specifying a length deprecated. Won't happen though.

If you raise it as a suggestion on connect I'll vote for it.


Tom
Post #1245078
Posted Wednesday, February 01, 2012 8:01 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:42 PM
Points: 41,516, Visits: 34,431
Question is, how far do you go?

Just char, varchar, nchar, nvarchar, binary, varbinary?
Also decimal and numeric (default is numeric(18,0))?
Also time (default is time(7)), datetime2 (default is datetime2(7)) and datetimeoffset (default is datetimeoffset(7))?

The new datetime and time default to their highest precision. Numeric and decimal default to something in the middle. The character and binary types default to their minimum when declared.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1245083
Posted Wednesday, February 01, 2012 8:04 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Monday, March 10, 2014 9:39 AM
Points: 579, Visits: 27,690
I lay my vote for that declaration of varchar/char/nvarchar/nchar/binary/varbinary/etc data types without specifying length should throw an error (or at least warning) by the parser. Anyone, lead me and I will follow . Maybe this issue is already raised at Microsoft ...
Post #1245084
Posted Wednesday, February 01, 2012 8:11 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Monday, March 10, 2014 9:39 AM
Points: 579, Visits: 27,690
GilaMonster (2/1/2012)
Question is, how far do you go?

Just char, varchar, nchar, nvarchar, binary, varbinary?
Also decimal and numeric (default is numeric(18,0))?
Also time (default is time(7)), datetime2 (default is datetime2(7)) and datetimeoffset (default is datetimeoffset(7))?

The new datetime and time default to their highest precision. Numeric and decimal default to something in the middle. The character and binary types default to their minimum when declared.


I want to go all the way . Thanks Gail for adding these. Everywhere were length or precision can be specified. Maybe, a warning message would be the most elegant and a good compromise.

Cheers
Istvan
Post #1245087
Posted Wednesday, February 01, 2012 8:14 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 4:56 PM
Points: 8,271, Visits: 8,717
GilaMonster (2/1/2012)
Question is, how far do you go?

Just char, varchar, nchar, nvarchar, binary, varbinary?
Also decimal and numeric (default is numeric(18,0))?
Also time (default is time(7)), datetime2 (default is datetime2(7)) and datetimeoffset (default is datetimeoffset(7))?

The new datetime and time default to their highest precision. Numeric and decimal default to something in the middle. The character and binary types default to their minimum when declared.

I think the default precisions for time, datetime2 and datetimeoffset are sensible, so although I have a general feeling that precision defaults are not a good thing I guess I can live with the defaults for those three.

Decimal and Numeric have such bizarre rounding and precision/scale adjustment conventions that it seems pure insanity to have defaults for precision and scale, since the effects could be disastrous; so I'd prefer it to be forbidden to omit precision and scale for these types (actually I'd prefer MS to implement the 2008 revision of the floating point standard so that we could have exponents to base 10 and deprecate decimal, numeric, money and smallmoney, but there's no chance of that in the short or medium term, and probably very little chance even in the long term).


Tom
Post #1245090
« Prev Topic | Next Topic »

Add to briefcase «««12345»»

Permissions Expand / Collapse