Home  >  Article  >  Database  >  Vertica修改带UNIQUE约束字段的长度

Vertica修改带UNIQUE约束字段的长度

WBOY
WBOYOriginal
2016-06-07 15:56:362684browse

表结构如 CREATE TABLE IF NOT EXISTS public.user ( id PRIMARY KEY, name varchar(32) NOT NULL UNIQUE, ...... ); 修改语句 alter table public.user alter name set data type varchar(52); 由于受“UNIQUE”条件的约束,如果直接执行语句将会报如下错误

表结构如

CREATE TABLE IF NOT EXISTS public.user (
id PRIMARY KEY,
name varchar(32) NOT NULL UNIQUE,
......
);

修改语句

alter table public.user alter name set data type varchar(52);

由于受“UNIQUE”条件的约束,如果直接执行语句将会报如下错误:

ROLLBACK 2350: Cannot alter type of column "name" since it is referenced in the constraint "C_UNIQUE_1"

所以要先删除“UNIQUE”约束

alter table wb_play.user drop CONSTRAINT C_UNIQUE_1 CASCADE;

再执行

alter table public.user alter name set data type varchar(52);

然后重新加上“UNIQUE”约束

alter table public.user add CONSTRAINT C_UNIQUE_1 UNIQUE(name);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn