SQL Server - script to update database columns from varchar to nvarchar if not already nvarchar(SQL Server - 将数据库列从 varchar 更新为 nvarchar(如果还不是 nvarchar)的脚本)
问题描述
我必须使用脚本将现有数据库结构从 varchar 更新为 nvarchar.由于每次运行配置应用程序时都会运行此脚本,因此我宁愿确定列是否已更改为 nvarchar,而不是对表执行更改.我必须支持的数据库是 SQL Server 2000、2005 和 2008.
I am in a situation where I must update an existing database structure from varchar to nvarchar using a script. Since this script is run everytime a configuration application is run, I would rather determine if a column has already been changed to nvarchar and not perform an alter on the table. The databases which I must support are SQL Server 2000, 2005 and 2008.
推荐答案
以下查询应该可以满足您的需求:
The following query should get you what you need:
IF EXISTS
(SELECT *
FROM sysobjects syo
JOIN syscolumns syc ON
syc.id = syo.id
JOIN systypes syt ON
syt.xtype = syc.xtype
WHERE
syt.name = 'nvarchar' AND
syo.name = 'MY TABLE NAME' AND
syc.name = 'MY COLUMN NAME')
BEGIN
ALTER ...
END
这篇关于SQL Server - 将数据库列从 varchar 更新为 nvarchar(如果还不是 nvarchar)的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server - 将数据库列从 varchar 更新为 nvarchar(如果还不是 nvarchar)的脚本
基础教程推荐
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在多列上分布任意行 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
