更改 varchar 列的最大长度?

时间:2022-11-24
本文介绍了更改 varchar 列的最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在不丢失内容的情况下将 varchar 列的长度从 255 个字符更新为 500 个字符.我之前删除并重新创建了表,但我从未接触过 alter 语句,我相信我需要使用它来执行此操作.我在这里找到了文档:ALTER TABLE (Transfact-SQL) 但是我不能让它正面或反面.

I'm trying to update the length of a varchar column from 255 characters to 500 without losing the contents. I've dropped and re-created tables before but I've never been exposed to the alter statement which is what I believe I need to use to do this. I found the documentation here: ALTER TABLE (Transfact-SQL) however I can't make heads or tails of it.

到目前为止,我有以下内容(不幸的是,基本上没有):

I have the following so far (essentially nothing unfortunately):

alter table [progennet_dev].PROGEN.LE
alter column UR_VALUE_3

我该如何解决这个问题?是否有关于此语句的更好的文档(我搜索了一些示例语句,但结果为空)?

How do I approach this? Is there better documentation for this statement out there (I did some searches for an example statement but came up empty)?

推荐答案

您需要

ALTER TABLE YourTable ALTER COLUMN YourColumn <<new_datatype>> [NULL | NOT NULL]

但请记住,如果需要,请明确指定 NOT NULL.

But remember to specify NOT NULL explicitly if desired.

ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500) NOT NULL;

如果你不指定如下...

If you leave it unspecified as below...

ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500);

然后该列将默认允许空值,即使它最初定义为 NOT NULL.即省略 ALTER TABLE ... ALTER COLUMN 中的规范总是被视为.

Then the column will default to allowing nulls even if it was originally defined as NOT NULL. i.e. omitting the specification in an ALTER TABLE ... ALTER COLUMN is always treated as.

ALTER TABLE YourTable ALTER COLUMN YourColumn VARCHAR (500) NULL;

此行为不同于用于使用 ALTER TABLE(或在 CREATE TABLE 时间)创建的新列的行为.默认的可空性取决于 ANSI_NULL_DFLT设置.

This behaviour is different from that used for new columns created with ALTER TABLE (or at CREATE TABLE time). There the default nullability depends on the ANSI_NULL_DFLT settings.

这篇关于更改 varchar 列的最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:如何更新 T-SQL 中的 DateTime 字段? 下一篇:SQL 查询中 SELECT 语句中 WITH TIES 关键字的用途是什

相关文章

最新文章