問題描述
我試圖在不丟失內容的情況下將 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模板網!