The command should be;
ALTER TABLE mythirdTable
ALTER COLUMN [Column2] varchar(3) NOT NULL
Main Topics
Browse All TopicsExperts,
I am updating a column datatype integer to varchar(3) with the following script
ALTER TABLE mythirdTable
ALTER COLUMN [Column2] [varchar] (3) NOT NULL
after changiging the column type, i am inserting values in to my table and still getting the error related to the data type of the column I have changed. Can you please help why this is happening or if I am doing anything wrong?
INSERT INTO mythirdTable
(Column1,Column2,Column3,C
VALUES
('3Jh45','2G8' ,'Test',10,4)
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '2G8' to a column of data type int.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for helping me out guys and I am trying to change data type for another column to the same table. But getting the follwing error
Server: Msg 5074, Level 16, State 1, Line 11
The object 'DF_myThirdTable_Column5' is dependent on column 'Column5'.
Server: Msg 4922, Level 16, State 1, Line 11
ALTER TABLE ALTER COLUMN column5 failed because one or more objects access this column.
I ran to sp_help to see what's this and here are the details
Constraint_type : DEFAULT on column Column5
Constraint_name : DF_myThirdTable_Column5
delete_action : n/a
update_action : n/a
status_enables : n/a
status_for_replication : n/a
Constraint_keys : (0)
so can i use the following script (wich is incomplete)
==========================
ALTER TABLE myThirdtable
DROP CONSTRAINT DF_myThirdTable_Column5
==========================
ALTER COLUMN [column5] varchar (3) NOT NULL
==========================
I am not sure how to add it back once I drop the constraint which has a defaulue as "0"
ALTER TABLE myThirdtable WITH NOCHECK ADD
CONSTRAINT [DF_myThirdTable_Column5]
(
[Column5]
) WITH FILLFACTOR = 90 ON ..???
can you please tell me or correct my code to add it back the default constraint?
Thanks again for all your wonderful help
Business Accounts
Answer for Membership
by: SweatCoderPosted on 2006-11-28 at 13:36:32ID: 18031715
Try this instead:
ALTER TABLE mythirdTable
ALTER COLUMN [Column2] varchar(3) NOT NULL