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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Massive Search and Replace

Author  Topic 

seesyong
Starting Member

1 Post

Posted - 2007-01-11 : 13:12:28
I need to update all the tables in my database to use nvarchar instead of varchar. Is there a way to update the database so that it will find all instances of varchar and replace it with nvarchar?

Also, I need to update all the stored procedures in the database to use nvarchar instead of varchar? Is this possible? What commands should I use to do this? Thanks!

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-01-11 : 16:47:15
You would need to write a script to first iterate through all your tables in the db with a subscript that iterates through each column. It can be done, but it'll take some time to lookup the proper way to do so. The only way I can think of to accomplish this would be to use a cursor with the results of

SELECT * FROM sysobjects
WHERE xtype='U'

Then do a sub cursor with the results of
sp_columns @table_name=@CursorResult

You would need to check the type of the column and if it was varchar change it.

It's going to take alittle research to complete but hopfully this helps.
Go to Top of Page
   

- Advertisement -