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


one character of data


one character of data

Author
Message
VM-723206
VM-723206
Right there with Babe
Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)Right there with Babe (776 reputation)

Group: General Forum Members
Points: 776 Visits: 267
Comments posted to this topic are about the item one character of data
Eswin
Eswin
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1959 Visits: 1078
i think the ans is varchar(1).

Tanx :-D
ChiragNS
ChiragNS
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3465 Visits: 1865
Since it wont be empty or null Char(1) is the right answer to this question.

"Keep Trying"
MarkusB
MarkusB
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5893 Visits: 4208
I've chosen for nchar(1) because it only says that the value won't be NULL or empty, but there's no limitation on the characters used. Also depending on your collation sometimes a character is covered by char but in another collation it's a nchar.

Try this:
CREATE TABLE #Chars(
c1 char(1) COLLATE SQL_Latin1_General_Cp850_BIN,
c2 nchar(1)COLLATE SQL_Latin1_General_Cp850_BIN,
c3 char(1)COLLATE SQL_Latin1_General_CP1_CI_AS,
c4 nchar(1)COLLATE SQL_Latin1_General_CP1_CI_AS)

INSERT INTO #chars
VALUES(CHAR(0128),CHAR(0128),CHAR(0128),CHAR(0128))

SELECT * FROM #chars
DROP TABLE #chars



As you can see the nchar value is consistent, while the char value depends on the collation.

Markus Bohse
Edmund Ward
Edmund Ward
SSC Veteran
SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)SSC Veteran (214 reputation)

Group: General Forum Members
Points: 214 Visits: 119
I agree with MarkusB. I chose nchar(1). There's nothing in the question to suggest that this single character of data will be limited to single-byte chars. You set yourself up for trouble later if you don't anticipate all potential data.
Pyay Nyein
Pyay Nyein
SSC-Enthusiastic
SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)SSC-Enthusiastic (133 reputation)

Group: General Forum Members
Points: 133 Visits: 404
"Either char(1) or varchar(1) may be used. Both would allocate 1 byte of space which would be used. "

doesn't varchar take extra 2 bytes for variant length? I think char(1) allocate 1 byte while varchar(1) allocate 3 bytes.
MarkusB
MarkusB
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5893 Visits: 4208
Yes, varchar(1) is definitly wrong.
Also the question wasn't which datatype uses the least space, but what is best.
But how do you define best?

Markus Bohse
Ben Leighton
Ben Leighton
Say Hey Kid
Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)

Group: General Forum Members
Points: 662 Visits: 359
surely nchar(1)?
Rutger-969691
Rutger-969691
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 86
I was thinking beyond US-ASCII, so I chose nchar(1) :-)
Martin_Burton
Martin_Burton
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1357 Visits: 602
The question is open to interpretatation, but i have to agree that is should be nchar(1)
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