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.
| Author |
Topic |
|
elin
Starting Member
2 Posts |
Posted - 2009-09-04 : 11:03:09
|
| Hi Folks,I have an existing column of data type varchar that I need to change to nvarchar, however I do not want to alter the existing column width of (5).If I use the following statement ALTER TABLE MYTABLE ALTER COLUMN MYCOLUMN NVARCHAR (5) NOT NULL I end up with a column of nvarchar data type, but with a column width of (10)! If I try the following statement without specifying a column width ALTER TABLE MYTABLE ALTER COLUMN MYCOLUMN NVARCHAR (5) NOT NULL I then end up with an nvarchar column with a width of (2)How can I simply change the column data type from varchar to nvarchar without affecting the existing column width?Thank you! |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-04 : 11:43:19
|
Whatever you did with your ALTER statement below is correct. quote: ALTER TABLE MYTABLE ALTER COLUMN MYCOLUMN NVARCHAR (5) NOT NULL
The column can still take only 5 characters. quote: SQL Server provides both datatypes to store character information. For the most part the two datatypes are identical in how you would work with them within SQL Server or from an application. The difference is that nvarchar is used to store unicode data, which is used to store multilingual data in your database tables. Other languages have an extended set of character codes that need to be saved and this datatype allows for this extension. If your database will not be storing multilingual data you should use the varchar datatype instead. The reason for this is that nvarchar takes twice as much space as varchar, this is because of the need to store the extended character codes for other languages.
|
 |
|
|
elin
Starting Member
2 Posts |
Posted - 2009-09-04 : 11:45:26
|
| Thank you vijayisonly - you are exactly correct!I was using sp_help tablename to determine the column length (which showed twice what it should be), however when I looked at the column properties, the column length was correct.Thank you for your help! |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-04 : 12:01:32
|
| np...you're welcome. |
 |
|
|
|
|
|