|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Saturday, April 06, 2013 12:20 AM
Points: 649,
Visits: 263
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 4:19 AM
Points: 1,593,
Visits: 1,025
|
|
i think the ans is varchar(1).
Tanx
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
|
|
Since it wont be empty or null Char(1) is the right answer to this question.
"Keep Trying"
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 3:22 AM
Points: 4,218,
Visits: 3,875
|
|
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
|
|
|
|
|
SSC 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.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Today @ 3:49 AM
Points: 95,
Visits: 343
|
|
"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.
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 3:22 AM
Points: 4,218,
Visits: 3,875
|
|
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
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, July 05, 2011 8:18 AM
Points: 582,
Visits: 359
|
|
|
|
|
|
SSC 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)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 11:11 AM
Points: 1,242,
Visits: 473
|
|
| The question is open to interpretatation, but i have to agree that is should be nchar(1)
|
|
|
|