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 列的最大长度?
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
