Changing the maximum length of a varchar column?(更改 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 列的最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改 varchar 列的最大长度?


基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01