|
Home > Archive > MS SQL Data Warehousing > November 2006 > Script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Erencan SAŠIROŠLU 2006-11-02, 7:12 pm |
| Hi Folks,
I need a script that it'll changed varchar field to nvarchar a table which i
pass it's name via parameter.
I generated it but it'll raise exception when a field has foreign key etc...
I don't want to spend more time to this work. Do you have a script like
this? Or program?
If you have it could you share with me?
Thanks.
| |
| John Bell 2006-11-02, 7:12 pm |
| Hi
If you try and change a column's data type and the column is referenced by a
foreign key, or is part of a primary key will give you an error. You will
need to drop these before trying to change the columns datatype. The easiest
way would be to script them, drop them and re-create them afterwards. To drop
them see http://www.mssqlserver.com/scripts/drop_keys.sql
John
"Erencan SAĆIROĆLU" wrote:
> Hi Folks,
> I need a script that it'll changed varchar field to nvarchar a table which i
> pass it's name via parameter.
> I generated it but it'll raise exception when a field has foreign key etc...
> I don't want to spend more time to this work. Do you have a script like
> this? Or program?
>
> If you have it could you share with me?
> Thanks.
>
>
>
| |
| Erencan SAŠIROŠLU 2006-11-02, 7:12 pm |
| Thanks John, but i want to foreign keys add again after change data type.
This script just drop foreign keys. :(
"John Bell" < jbellnewsposts@hotma
il.com> wrote in message
news:55E6E65D-A653-4620-A2D3- C4BEB4A224AC@microso
ft.com...[color=darkred]
> Hi
>
> If you try and change a column's data type and the column is referenced by
> a
> foreign key, or is part of a primary key will give you an error. You will
> need to drop these before trying to change the columns datatype. The
> easiest
> way would be to script them, drop them and re-create them afterwards. To
> drop
> them see http://www.mssqlserver.com/scripts/drop_keys.sql
>
> John
>
> "Erencan SADIRODLU" wrote:
>
| |
| John Bell 2006-11-02, 7:12 pm |
| Hi
But you could script them first, which is what I indicated in the response.
There are several ways to do this, as this is a one off job use Enterprise
Manager. If you take a backup before making any changes and restore the
database under a different name, you could use a tool such as Red Gate's SQL
Compare to check the differences (in fact you could use this to re-apply the
missing FKs and PKs).
John
"Erencan SAĆIROĆLU" wrote:
> Thanks John, but i want to foreign keys add again after change data type.
> This script just drop foreign keys. :(
>
>
> "John Bell" < jbellnewsposts@hotma
il.com> wrote in message
> news:55E6E65D-A653-4620-A2D3- C4BEB4A224AC@microso
ft.com...
>
>
>
|
|
|
|
|