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

one character of data Expand / Collapse
Author
Message
Posted Thursday, June 4, 2009 9:13 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Thursday, December 11, 2014 5:11 AM
Points: 654, Visits: 267
Comments posted to this topic are about the item one character of data
Post #729388
Posted Thursday, June 4, 2009 9:39 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, October 28, 2013 8:50 AM
Points: 1,606, Visits: 1,039
i think the ans is varchar(1).

Tanx
Post #729393
Posted Friday, June 5, 2009 2:05 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 8:08 AM
Points: 2,365, Visits: 1,846
Since it wont be empty or null Char(1) is the right answer to this question.

"Keep Trying"
Post #729465
Posted Friday, June 5, 2009 2:18 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 5:31 AM
Points: 4,429, Visits: 4,183
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
Post #729471
Posted Friday, June 5, 2009 2:54 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, April 30, 2012 2:32 AM
Points: 202, 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.
Post #729488
Posted Friday, June 5, 2009 3:00 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, October 3, 2014 8:06 AM
Points: 95, Visits: 368
"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.
Post #729491
Posted Friday, June 5, 2009 3:10 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 5:31 AM
Points: 4,429, Visits: 4,183
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
Post #729496
Posted Friday, June 5, 2009 3:10 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: Tuesday, July 5, 2011 8:18 AM
Points: 582, Visits: 359
surely nchar(1)?
Post #729497
Posted Friday, June 5, 2009 3:22 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, April 18, 2013 5:50 AM
Points: 90, Visits: 86
I was thinking beyond US-ASCII, so I chose nchar(1)
Post #729504
Posted Friday, June 5, 2009 3:34 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, December 9, 2014 12:10 PM
Points: 1,341, Visits: 558
The question is open to interpretatation, but i have to agree that is should be nchar(1)
Post #729510
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse