• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

更改 varchar 列的最大长度?

用户头像
it1352
帮助1

问题说明

我试图在不丢失内容的情况下将 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)?

正确答案

#1

您需要

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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangibkka
系列文章
更多 icon
同类精品
更多 icon
继续加载