更改 varchar 列的最大长度?

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Number of working days between two dates(两个日期之间的工作日数)
How do I use dateadd to get the first day of last year?(如何使用 dateadd 获取去年的第一天?)
SQL- Count occurrences of a specific word within all stored procedures(SQL- 计算所有存储过程中特定单词的出现次数)
SQL query to make a column of numbers a string(使一列数字成为字符串的 SQL 查询)
T-SQL: Best way to replace NULL with most recent non-null value?(T-SQL:用最新的非空值替换 NULL 的最佳方法?)
Count days in date range with set of exclusions which may overlap(使用一组可能重叠的排除项计算日期范围内的天数)