Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 CHAR TO VARCHAR

Author  Topic 

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-06 : 00:58:23
Dear all,

IN OUR PROJECT WE ARE USING CHAR DATATYPE. BUT I FEEL THE CHAR DATA TYPE IS SLOWER RATHER THAN VARCHAR.
IS RIGHT. IS IT POSSIBLE TO CONVERT ALL CHAR TO VARCHAR..? IS IT RAISE ANY PROBLEMS..?


Thanks
KK

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-06-06 : 01:47:25
I dont think it will raise to any hassles. Just see to it that you define a proper length for the
varchar.

Chirag
Go to Top of Page

cmdr_skywalker
Posting Yak Master

159 Posts

Posted - 2006-06-06 : 02:06:17
CHAR and VARCHAR have adv. and disadv. Read BOL for more info. However, using CHAR to the extreme can cause havoc. CHAR forces the allocation of the space as specified in the length declaration. VARCHAR depends on the amount. To some extent, it will. For instance, you have 1M rec using column declared as CHAR(8000). Compare this to 1M record with column declared as VARCHAR(8000) but the actual length is 8 bytes. To read 100K records, and assuming uniform distribution, the SQL Server will read 100K extent for CHAR unlike with approx. 100 extents for VARCHAR (excluding the overhead).

May the Almighty God bless us all!
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-06-06 : 02:21:57
"I dont think it will raise to any hassles"

I'd be surprised if it doesn't!

Changing from fixed length, space padded, data to variable length with no trailing spaces (actually potentially with any trailing spaces that the user has chosen to enter!) sounds like a significant change that will trip up the application to me.

But I only ever use CHAR for fixed length data with no trailing spaces, so I don't know how "silently" SQL Server handles the space-padding.

Kristen
Go to Top of Page

CSK
Constraint Violating Yak Guru

489 Posts

Posted - 2006-06-06 : 02:30:11
Thanks Guys
Go to Top of Page
   

- Advertisement -