473,546 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alter Table - Change Column Datatype

Hi,

I want to change the datatype of an existing column from char to
varbinary. When I run the "Alter Table" statement, I get the
following error message -

Disallowed implicit conversion from data type char to data type
varbinary, table 'test.dbo.testa lter', column 'col1'. Use the CONVERT
function to run this query.

Can the CONVERT function be used as part of an alter table/alter
column? Is there another way besides renaming the table and creating
a new one?

Thanks,
Bruce
Jul 20 '05 #1
1 21248
On 19 Apr 2004 11:29:46 -0700, Bruce wrote:
Hi,

I want to change the datatype of an existing column from char to
varbinary. When I run the "Alter Table" statement, I get the
following error message -

Disallowed implicit conversion from data type char to data type
varbinary, table 'test.dbo.testa lter', column 'col1'. Use the CONVERT
function to run this query.

Can the CONVERT function be used as part of an alter table/alter
column? Is there another way besides renaming the table and creating
a new one?

Thanks,
Bruce


Yes, there is another way: rename not the whole table, but just the
column, then create a new one:

EXEC sp_rename 'test.dbo.testa lter.col1' 'col1old', COLUMN
go
ALTER TABLE test.dbo.testal ter
ADD col1 varbinary(321) NULL
-- If it has to be NOT NULL, change this to read
-- ADD col1 varbinary(321) NOT NULL DEFAULT 0
go
UPDATE test.dbo.testal ter
SET col1 = CAST(col1old AS varbinary(321))
go
ALTER TABLE test.dbo.testal ter
DROP COLUMN col1old
go
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9814
by: Dylan Nicholson | last post by:
Seems that Oracle 9.2 (using MS ODBC driver) requires extra parentheses when adding multiple columns to a table: ALTER TABLE MyTable ADD (MyColumn1 VARCHAR(255), MyColumn2 VARCHAR(255)) vs ALTER TABLE MyTable ADD MyColumn1 VARCHAR(255), MyColumn2 VARCHAR(255)
2
15029
by: Laurence Breeze | last post by:
Is it possible to add a column to a table using the "alter table" statement and specify where in the sequence of columns the new column sits. If not is there any way to alter the order of columns using TSQL rather than Enterprise Manager / Design Table. TIA Laurence Breeze
1
15230
by: Bruce | last post by:
Hi, I want to change the datatype of an existing column from char to varbinary. When I run the "Alter Table" statement, I get the following error message - Disallowed implicit conversion from data type char to data type varbinary, table 'test.dbo.testalter', column 'col1'. Use the CONVERT function to run this query.
1
6682
by: p175 | last post by:
People, I have the following table and I need to add a column that uses a the listed UDF to count the number of days within specific quarters by year. CREATE TABLE HISTORY_MB ( ID INTEGER NOT NULL, DAYS_RL INTEGER NOT NULL, DAYS_RH INTEGER NOT NULL, DAYS_RB INTEGER NOT NULL, QTR SMALLINT NOT NULL,
2
3563
by: Tim Newton | last post by:
Hi I have a vb app that uses an access database to store information. This app has been distributed to several users. I would like to increase the size of a field in an access table using my vb app so the users dont have to input all their data again, what is the best way to do it. I normally use oracle and would call something like an...
5
49669
by: Mike L | last post by:
Hello all I'm trying to migrate a BE from Access to SQL Server. I've been making changes to the Access BE from the FE with SQL statements, and want to do the same with the BE in SQL Server. When running the statement "ALTER TABLE tblTest DROP COLUMN TestColumn3" from the FE with a SQL Server BE, it works OK. Running the statement...
6
11200
by: Sam | last post by:
Hi Here is my code : Code: Dim dt As New DataTable dt.Columns.Add.ColumnName = "New" dt.Columns("New").DataType = System.Type.GetType("System.String") dt.Columns.Add.ColumnName = "Id" dt.Columns("Id").DataType = System.Type.GetType("System.Integer")
6
12209
by: terenceyuen | last post by:
I would like to change the type of Null to NO ,what is the command for this? I've tried this one, but no luck to get it work. ALTER TABLE claims_summary ALTER COLUMN advance_call_details SET NOT NULL; Thanks. Terence +----------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | ...
0
1589
by: kleach | last post by:
If I have a large(200gb), medium width(300 bytes) table and need to add a column, we have always unloaded data, dropped and recreated the table then loaded data again to ensure performance. What is the cost of using alter table on future queries?
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.