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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Change newID varchar datatype to INT datatype.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2013-04-02 : 09:27:09
Dear All,

I have one column with newID Varchar(36). Our team plan to change it to INT.
Can anyone please tell me how to change the datatype ? So my existing columns value also will change to INT datatype (like 1,2,3 etc).

Thanks and Regard's
Harish Patil

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-04-02 : 09:38:10
Read it out.. hope it helps
http://blog.sqlauthority.com/2010/10/18/sql-server-change-column-datatypes/

Cheers
MIK
Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2013-04-02 : 10:05:49
Dear Mik,

You min to say If I will alter the column to INT then it reflect the values into table also.
Now I am store varchar(36) with newID() means ID getting store 36 varchar. If I am changing to INT then automatically my column value also will change to 1,2,3 etc.

Write?

Thanks and Regard's
Harish Patil
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-04-02 : 12:07:50
So you have a VARCHAR(36) column that is storing GUIDs and you want to convert that column to an INT? What ae your business rules for converting a GUID to an INT?

Or are you saying you want to replace the VARCHAR(36) column with an IDENTITY column?

This is where posting a proper question with DDL, DML and expected output really helps us to help you. Here are some links on how to post your question so that it is easier for us to help you and you can get tested code:

http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-04-02 : 12:51:29
quote:
Originally posted by hspatil31

Dear Mik,

You min to say If I will alter the column to INT then it reflect the values into table also.
Now I am store varchar(36) with newID() means ID getting store 36 varchar. If I am changing to INT then automatically my column value also will change to 1,2,3 etc.

Write?

Thanks and Regard's
Harish Patil



It was with assumption that the data is currently in integer format in a column having datatype as varchar. But if the data is in string format then alter won't even work and will throw an error.
So as Lamprey mention, we need more explanation.

Cheers
MIK
Go to Top of Page
   

- Advertisement -