如果列是特定类型,我如何检查 MS SQL Server 2005 [英] How can i check in MS SQL Server 2005 if a column is of a specific type

查看:26
本文介绍了如果列是特定类型,我如何检查 MS SQL Server 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 MS SQL Server 2005 中更改列的类型,但在更改该列的类型之前,我想检查该列是否属于我想要更改的类型.我如何在 SQL 中做到这一点?

I want to change the type of a column in MS SQL Server 2005, but before i change the type of that column i want to check if that column is of the type i want to change. How can i do that in SQL?

谢谢,巴斯亨德里克斯.

Thanxs, Bas Hendriks.

基于 anwser,我编写了以下查询来解决问题:

Based on the anwser i wrote the following query that did the trick:

        IF NOT EXISTS (SELECT *
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'e_application'
            AND COLUMN_NAME = 'txt_locked_by'
            AND DATA_TYPE = 'nvarchar'
            AND CHARACTER_MAXIMUM_LENGTH = 15 )
        BEGIN
            ALTER TABLE.....
        END

推荐答案

您可以查询INFORMATION_SCHEMA 表.

You can query the INFORMATION_SCHEMA tables.

例如

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'MyTable'

这篇关于如果列是特定类型,我如何检查 MS SQL Server 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆