SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Question of the Day for 01 Dec 2005


Question of the Day for 01 Dec 2005

Author
Message
Site Owners
Site Owners
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: Administrators
Points: 18595 Visits: 222
Comments posted to this topic are about the Question of the Day for 01 Dec 2005 posted at http://www.sqlservercentral.com/testcenter/qod.asp?QuestionID=654.
Mads Holm-152675
Mads Holm-152675
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 3

The funny thing is that in

select cast('This is a test' as varchar)

the varchar size defaults to 30, so in this case the full string is returned.


MattieNH
MattieNH
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5115 Visits: 901

That's probably tomorrow's question.

I looked at the MSDN reference, and it had the following line:

The SQL-2003 synonym for char is character.

What is SQL-2003?

Mattie





BobAtDBS
BobAtDBS
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1848 Visits: 373

Yeah, I noticed that too. Probably what SQL - 2005 was supposed to be!

I also saw a new feature that I think I'll really like

Declare @i varchar(max)

Gives you a rather large text store without the text datatype's limitations? Cool.




Student of SQL and Golf, Master of Neither
SQLBill
SQLBill
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25236 Visits: 1087
While it was correct, the answer wasn't complete. Per BOL, VARCHAR defaults to 1 when it's used in a data definition or variable declaration statement. BUT it defaults to 30 when used with CAST.

-SQLBill



BobAtDBS
BobAtDBS
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1848 Visits: 373

Well, as long as we're being picky, it defaults to 50 when you're using EM to define a field too.

But, if you take the question literally as presented, the answer was correct. And that's all that really counts for a test.




Student of SQL and Golf, Master of Neither
Yelena Varshal
Yelena Varshal
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18738 Visits: 608

Hi,

The BOL topic "Char and Varchar" says:

".....Remarks

When n is not specified in a data definition or variable declaration statement, the default length is 1. When n is not specified with the CAST function, the default length is 30...."

In the Enterprise Manager you do specify n. 50 is a suggested length. It does not let you to select nothing for n, posts a message that n must be from 1 to 8000. Enterprise Manager is a client application which may have any restrictions specified by its programmers (Microsoft in this case) where TSQL statements and its rules are applicable to server software SQL Server.




Regards,
Yelena Varshal

David Frommer
David Frommer
SSC Veteran
SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)SSC Veteran (286 reputation)

Group: General Forum Members
Points: 286 Visits: 9
In response to what is SQL 2003. That likely does not refer to SQL Server 2003, but, the ANSI SQL 2003 standard.
kapil_kk
kapil_kk
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10635 Visits: 2778
nice and easy question....:-)

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search