SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Change newID varchar datatype to INT datatype.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

hspatil31
Posting Yak Master

182 Posts

Posted - 04/02/2013 :  09:27:09  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/02/2013 :  09:38:10  Show Profile  Reply with Quote
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 - 04/02/2013 :  10:05:49  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/02/2013 :  12:07:50  Show Profile  Reply with Quote
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

Edited by - Lamprey on 04/02/2013 12:17:20
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 04/02/2013 :  12:51:29  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000