Tuesday 15 June 2010

In SQL Server change column of type int to type text -


I want to type to type the column, in order to type the column in SQL Server while retaining the column name. There are so many data in the table with this column, and I do not want to lose it. In order to support SQL Server built-in or clear, text does not appear to be int, otherwise it will be very easy. So, how would you use it only in SQL?

Since MS SQL server (like most databases) does not support directly changing the type of an existing column You have to do it in phases, the way I have solved such problems in the past (assuming that your name is 'Fu' and your column is 'Bar'):

  Add text to the column template for the optional column Foo; Update foo SET tempbar = cast (cast (repeatedly as text)); Optional Table Foo Drop Column Bar; Add text to optional table foo column bar; Update foo SET bar = tempbar; Optional table fu drop column temp;  

(Some SQL syntax may be shut down, it's been a year since I last did it, at a different job, so I have access to MS SQL Server or Source If you have an index in your column, then you have to do more stuff.)

Props for conversion syntax.

[edit]

tempbar as bar (step 4-6 of Instead) to change the name of the stored procedure has been suggested. This is an MS SQL Server-specific solution that can work for many situations, the solution I described is on any SQL database (with syntax modification) regardless of the version Will work. In my case, I was working with primary and foreign keys, and there was not only one area, so I had to order all the tasks carefully and the port of MS SQL Server was to be portable - in my favor clearly Worked from / P>


No comments:

Post a Comment