将列的数据类型从 bigint 更改为 uniqueidentifier [英] Change datatype of column to uniqueidentifier from bigint

查看:40
本文介绍了将列的数据类型从 bigint 更改为 uniqueidentifier的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 sql server 中表中列的数据类型.我使用了以下语句:

I want to change the datatype of a column in a table in sql server. I used the following statement:

ALTER TABLE dbo.tbltest  
ALTER COLUMN ID uniqueidentifier

但它抛出错误

操作数类型冲突:bigint 与 uniqueidentifier 不兼容

Operand type clash: bigint is incompatible with uniqueidentifier

推荐答案

不能从整数转换为 uniqueidentifier.但你可以这样做.

You cannot convert from an integer to a uniqueidentifier. But you can do it like this.

  1. 首先从表中删除旧数据.

  1. First delete old data from the table.

将列更改为某种文本格式(例如 VARCHAR(200)).

Alter the column to some text-format (such as VARCHAR(200)).

ALTER TABLE dbo.tbltest  
ALTER COLUMN ID VARCHAR(200)

  • 又来了

  • Now again

    ALTER TABLE dbo.tbltest  
    ALTER COLUMN ID uniqueidentifier
    

  • 需要明确的是,您不能直接将列从数字转换为uniqueidentifier,但可以将numeric 转换为varchar 为<代码>唯一标识符.

    To be clear, you can't convert a column from numeric to uniqueidentifier directly, but you can convert numeric to varchar to uniqueidentifier.

    这篇关于将列的数据类型从 bigint 更改为 uniqueidentifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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