sql server - Alter Column: option to specify conversion function? -


i have column of type float contains phone numbers - i'm aware bad, want convert column float nvarchar(max), converting data appropriately not lose data.

the conversion can apparently handled correctly using str function (suggested here), i'm not sure how go changing column type , performing conversion without creating temporary column. don't want use temporary column because doing automatically bunch of times in future , don't want encounter performance impact page splits (suggested here)

in postgres can add "using" option alter column statement specifies how convert existing data. can't find tsql. there way can in place?

postgres example:

...alter column <column> type <type> using <func>(<column>); 

rather use temporary column in table, use (temporary) column in temporary table. in short:

  1. create temp table pk of table + column want change (in correct data type, of course)
  2. select data temp table using conversion method
  3. change data type in actual table
  4. update actual table temp table values

if table large, i'd suggest doing in batches. of course, if table isn't large, worrying page splits premature optimization since doing complete rebuild of table , indexes after conversion cheap. question is: why nvarchar(max)? data phone numbers. last time checked, phone numbers short (certainly less 2 gb nvarchar(max) can hold) , non-unicode. domain modeling figure out appropriate data size , you'll thank me later. lastly, why "automatically bunch of times in future"? why not have correct data type , insert right values?


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -