Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

Dependencies and VARCHAR/NVARCHAR...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Hunter Ross - 25 Jul 2008 22:07 GMT
I'll be as terse as possible... Our next product release will support
UNICODE, so all VARCHAR fields, casts, variables, and all usage will be
changed to NVARCHAR.  Hundreds of our customers databases will need to be
programatically upgraded.  We know how the databases SHOULD look; fields,
indexes, types, constraints, defaults, views, etc.

My technique is to first drop all SPs and VIEWS, then do benign ALTER TABLE
commands to eliminate UDF use; we'll drop/add UDFs redefined as equivelent
NVARCHAR later.  (I'm preparing to "alter table alter column" to actually
change several hundred fields from VARCHAR to NVARCHAR.)  Next, I drop
constraints/indexes/defaults (named and unnamed) from any VARCHAR fields.
Next, drop UDFs then add NVARCHAR UDFs with same names; this should be
possible at this point.  Next, all the "alter table alter column" commands,
where the actual conversion from VARCHAR to NVARCHAR occurs.  Finally, I
recreate all constraints/indexes/defaults that were dropped, recreated views
and procedures.  There are hundreds of fields.  (Some changes exceed the
~8039 byte row size, so we are shrinking some of them too.)

Anyway, it works, usually.  I keep batches very small, and use simple
recovery mode during the conversion, and DB growth is typically much less
than I would have expected.

Finally, my problems... Our customers often add SPs, and sometimes special
indexes to support their specific needs, or specific performance issues.  At
the point where I am about to  "alter table alter column" and/or
"sp_droptype/sp_addtype" I'd like to warn and abort, rather than let some
rogue dependency cause failure.  (If that happens, so be it, our customers
will be on alert as will our support staff.)  I've looked at sp_depends and
sp_msdependencies, but neither seem quite appropriate.  I have a script I
used for a similar (2-byte numeric to 4-byte conversion) that reads
syscolumns/systypes/sysobjects/sysindexes/sysindexkeys, but dang!

Any words of help or guidance will be greatly appreciated.  This is a tough
project given the hundreds of fields and types, and further by the hundreds
of field databases across the planet.  Any reporting I can do prior to
actual "error" will help a little bit.

Thanks for reading, and thanks in advance for your words.  Sincerely,

James
Andrew J. Kelly - 25 Jul 2008 23:32 GMT
James,

First off I want to say good luck with it all because you will need it:).
You might consider looking at Red-Gate and ApexSql as I believe both have
very good dependency tools and again I believe they each have API's as well.
So you may be able to save yourself some work by utilizing their tools in
your efforts.  One other comment is that you may want to look at replacing
some of the large columns with MAX datatypes in which the rows are now too
large.

Signature

Andrew J. Kelly    SQL MVP
Solid Quality Mentors

> I'll be as terse as possible... Our next product release will support
> UNICODE, so all VARCHAR fields, casts, variables, and all usage will be
[quoted text clipped - 37 lines]
>
> James
James Hunter Ross - 25 Jul 2008 23:46 GMT
The "MAX" idea is good; I'll need to research it's availability for
200/2005/2008 as we will be performing these changes across each of those
SQL Server versions.

Thanks!
Andrew J. Kelly - 26 Jul 2008 00:42 GMT
If you have to support 2000 then you can't use the MAX datatype as it was
introduced in 2005. But maybe this is a good time to move off of 2000 as
well.

Signature

Andrew J. Kelly    SQL MVP
Solid Quality Mentors

> The "MAX" idea is good; I'll need to research it's availability for
> 200/2005/2008 as we will be performing these changes across each of those
> SQL Server versions.
>
> Thanks!
Eric Isaacs - 25 Jul 2008 23:37 GMT
> Any words of help or guidance will be greatly appreciated.  This is a tough
> project given the hundreds of fields and types, and further by the hundreds
> of field databases across the planet.  Any reporting I can do prior to
> actual "error" will help a little bit.

Just a thought, you don't really need to drop and recreate all the
sprocs, views, and udfs.  You could ALTER them.  The advantage of
ALTER is that if it fails, the old version is still in place.  Also,
any permissions are still maintained with an ALTER.

If you have any schema bound views or functions, you can alter them to
remove the schema binding, before altering the table to change out the
varchar to nvarchar, then alter the schema bound objects again to
change their varchar to nvarchar.

Indexes, constraints, and keys may need to be dropped first before
they can be changed, but you can list the indexes ahead of time to
determine any that are not anticipated.

Look into the built in INFORMATION_SCHEMA views which can provide
valuable information about the database.  You might consider comparing
the results of those views to your expected results and viewing the
differences between them to determine possible issues with the
conversion.  http://msdn.microsoft.com/en-us/library/ms186778.aspx

You'll also want update the statistics and recompile all the sprocs
after you've completed the conversion to make sure they're optimized
to the new design.

I hope that helps!

-Eric Isaacs
James Hunter Ross - 26 Jul 2008 00:01 GMT
Good advice.  I might have mistyped, I need to change UDTs (user-defined
data types, not user-defined functions), so we must drop/add, as far as I
know.  I should make use of INFORMATION_SCHEMA though, as long as there is
consistency across 200/2005/2008.

Thank you!
Eric Isaacs - 26 Jul 2008 00:59 GMT
On Jul 25, 4:01 pm, "James Hunter Ross" <james.r...@oneilsoft.com>
wrote:
> Good advice.  I might have mistyped, I need to change UDTs (user-defined
> data types, not user-defined functions), so we must drop/add, as far as I
> know.  I should make use of INFORMATION_SCHEMA though, as long as there is
> consistency across 200/2005/2008.
>
> Thank you!

INFORMATION_SCHEMA was in use back in SQL 7, so 2000, 2005, and 2008,
so you should have pretty good luck with it in each of the versions.

--Eric Isaacs
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.