Re: Change datatype on all table (HELP, HELP, rush)

From: KT (ktdev_at_hotmail.com)
Date: 05/18/04


Date: Tue, 18 May 2004 13:30:11 -0500

Thanks. Works great.

"Keith Kratochvil" <sqlguy.back2u@comcast.net> wrote in message
news:Or$3Z5PPEHA.1612@TK2MSFTNGP11.phx.gbl...
You will want to test this before running it on a production machine to make
sure that you do not loose any data...

/*this creates scripts that you will need to run*/
SELECT 'ALTER TABLE ' + table_name +
 ' ALTER COLUMN ' + COLUMN_NAME + ' varchar ' +
 ' (' + LTRIM(STR(CHARACTER_MAXIMUM_LENGTH)) + ')' +
 char(13) + char(10) + 'GO'
FROM information_schema.columns WHERE DATA_TYPE IN ('nvarchar')

-- 
Keith
"KT" <ktdev@hotmail.com> wrote in message
news:O0A7M1PPEHA.4008@TK2MSFTNGP09.phx.gbl...
> I need a way to change a datatype from nvarchar to varchar on all tables
> within a database.  Any help appreciated.
>
> Thanks
>
>


Relevant Pages

  • Re: Change datatype on all table (HELP, HELP, rush)
    ... You will want to test this before running it on a production machine to make sure that you do not loose any data... ... > I need a way to change a datatype from nvarchar to varchar on all tables ... > within a database. ...
    (microsoft.public.sqlserver.programming)
  • Re: Trouble moving db to another sql2005
    ... from one SQLServer (right-click on the database in the Management ... error that the on disk structure was 611 and the production machine ...
    (microsoft.public.sqlserver)
  • Re: Informix 7.30 (I know!)
    ... >We have a need to migrate the database from a running Production server on ... >to a Pre Production machine which will eventually replace the Production ... Wasn't "no downtime", but the total downtime was very ...
    (comp.databases.informix)
  • Re: PC joining domain
    ... If you loose a DC without demoting you have to do some steps to remove it complete from the AD database, DNS zones, AD sites and services: ...
    (microsoft.public.windows.server.active_directory)
  • Re: Deleted Transaction Logs!
    ... You will loose any uncomitted data and anything after the last CHECKPOINT, ... You can also create a new database with the same name, stop sql service and ... replace the data files with your original database and then start the ...
    (microsoft.public.sqlserver.server)