943,829 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 218425
  • MS SQL RSS
Jul 14th, 2005
0

Changing the datatype of a Column

Expand Post »
Hello,
I want to change the datatype of a field from Varchar to integer in T-SQL.

I tried something like Modify like you use in Oracle.

ALTER TABLE tablename
MODIFY COLUMNNAME Datatype.

But its not working in SQL server..

Any thoughts.
Similar Threads
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jul 14th, 2005
0

Re: Changing the datatype of a Column

i am not very sure is it different as in SQL where yu can go to the database that you want and then you go to the table and then you click the right side of yur mouse and go to design table and change it
Reputation Points: 10
Solved Threads: 0
Light Poster
wchitamb is offline Offline
31 posts
since Jul 2005
Jul 14th, 2005
0

Re: Changing the datatype of a Column

I changed it. I went to enterprise Manager and went to design view of the table and changed the data type of the field.

Thanks anyway
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jul 14th, 2005
0

Re: Changing the datatype of a Column

Thanks Wchitamb.
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jul 19th, 2005
0

Re: Changing the datatype of a Column

G'd evening!
In case you still need to change the table's column type from T-SQL , the sintax for MS SQL is:
ALTER TABLE table ALTER COLUMN column_name new_data_type
Ex.
ALTER TABLE MyTable ALTER COLUMN MyColumn NVARCHAR(20)

For more about the Alter Table sintax, read the books on line (BOL), here is the last update for SQL 2k SQL Server Books Online January 2004 Update
Good luck
Estuardo
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Estuardo is offline Offline
13 posts
since Jul 2005
Oct 30th, 2009
0
Re: Changing the datatype of a Column
thank u ESTUARDO for sending t-satatment on changing data type
Reputation Points: 10
Solved Threads: 0
Newbie Poster
munna barik is offline Offline
1 posts
since Oct 2009
Aug 10th, 2010
0
Re: Changing the datatype of a Column
ALTER TABLE table ALTER COLUMN column_name new_data_type
this will definitely work i got answer
thank you Estuardo
Last edited by mathewmoozh; Aug 10th, 2010 at 8:28 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mathewmoozh is offline Offline
15 posts
since Nov 2007
Mar 14th, 2011
0
Re: Changing the datatype of a Column
1 Question... how does 1 do this for a column with the data type char if you want tot take it to decimal... gives me an error on the conversion....

"Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric."

is there an additional way to write in a CONVERT for the data included in the field?
Reputation Points: 47
Solved Threads: 7
Junior Poster in Training
Eagletalon is online now Online
80 posts
since Mar 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Data Format in sql View
Next Thread in MS SQL Forum Timeline: Complex Query :: De-normalise!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC