简体   繁体   English

如何在SQL Server 2008中将所有varchar数据类型列更改为Nvarchar数据类型列

[英]How to change all varchar datatype columns to Nvarchar datatype columns in sql server 2008

I have a list of tables where i have to change VARCHAR datatype of all columns no NVARCHAR datatype. 我有一个表列表,在这里我必须更改所有列的VARCHAR数据类型,而无NVARCHAR数据类型。

While changing to NVARCHAR i should get all those not null and null columns. 当更改为NVARCHAR时,我应该获取所有非null和null列。 It should change the size of columns having >4000 to NVARCHAR(MAX) and want to change the size of primary key columns to 448 when converted to NVARCHAR.The primary key columns cause problem while converted to NVARCHAR when the size is above 448 due to index errors 它应将具有> 4000的列的大小更改为NVARCHAR(MAX),并在将其转换为NVARCHAR时要将主键列的大小更改为448.当主键列的大小大于448时,由于转换为NVARCHAR而引起问题索引错误

This query will give you a list of all varchar columns with length and nullability 该查询将为您提供所有具有长度和可空性的varchar列的列表

SELECT TABLE_CATALOG,
       TABLE_SCHEMA,
       TABLE_NAME,
       COLUMN_NAME,
       CHARACTER_OCTET_LENGTH,
       IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE='varchar'

Your question is unclear, for me to help more. 您的问题尚不清楚,请给我更多帮助。

While changing to NVARCHAR i should get all those not null and null columns 当更改为NVARCHAR时,我应该获取所有非null和null列

Does this mean you want to retain nullability property as is? 这是否意味着您想保留可空性属性? Please ask with more clarity. 请更清楚地询问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM