I have a table which has a VARCHAR(MAX)
column, and I need to change it to VARBINARY(MAX)
.
I tried using the command
ALTER TABLE TableName ALTER COLUMN ColumnName VARBINARY(MAX)
but I got the error
Msg 257, Level 16, State 3, Line 1
Implicit conversion from data type varchar(max) to varbinary(max) is not allowed.
Use the CONVERT function to run this query.
The table has no data, so I can't understand why it's complaining about data conversion.
3条答案
按热度按时间34gzjxbg1#
You cannot perform this conversion using an
ALTER TABLE
statement since converting fromvarchar(max)
tovarbinary(max)
requires an explicit conversion . So you should follow these steps to alter your table:VARBINARY(MAX)
VARCHAR(MAX)
column, use update statement to add the data to theVARBINARY
columnVARCHAR(MAX)
columnvarbinary
column tovarchar
name (per comment from @Ben Thul)e4yzc0pl2#
Convert
Varchar
toInt
and then changeInt
toBinary
.qlckcl4x3#
This worked for me:
ALTER TABLE studentlogins MODIFY password VARBINARY(255);