Vertica modifies the length of a field with a UNIQUE constraint.

Source: Internet
Author: User
The table structure is as follows: CREATETABLEIFNOTEXISTSpublic. user (idPRIMARYKEY, namevarchar (32) NOTNULLUNIQUE ,......); modify statement altertablepublic. useralternamesetdatatypevarchar (52); due to the constraints of the "UNIQUE" condition, the following error will be reported if the statement is executed directly.

The TABLE structure is as follows: 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); due to the constraints of the "UNIQUE" condition, the following error will be reported if the statement is executed directly.

The table structure is as follows:

Create table if not exists public. user (
Id primary key,
Name varchar (32) not null unique,
......
);

Modify statement

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

Due to the constraints of the "UNIQUE" condition, if the statement is executed directly, the following error will be reported:

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

Therefore, you must first Delete the "UNIQUE" constraint.

Alter table wb_play.user drop CONSTRAINT C_UNIQUE_1 CASCADE;

Run again

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

Then add the "UNIQUE" Constraint

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.