在H2中删除列的唯一约束 [英] Dropping unique constraint for column in H2

查看:80
本文介绍了在H2中删除列的唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在h2中删除列的唯一约束,该约束以前创建为 info varchar(255)unique

I try to drop unique constraint for column in h2, previously created as info varchar(255) unique.

我尝试过:

sql> alter table public_partner drop constraint (select distinct unique_index_name from in
formation_schema.constraints where table_name='PUBLIC_PARTNER' and column_list='INFO');

但没有成功(如下所示):

But with no success (as follows):

Syntax error in SQL statement "ALTER TABLE PUBLIC_PARTNER DROP CONSTRAINT ([*]SELECT DISTI
NCT UNIQUE_INDEX_NAME FROM INFORMATION_SCHEMA.CONSTRAINTS WHERE TABLE_NAME='PUBLIC_PARTNER
' AND COLUMN_LIST='INFO') "; expected "identifier"; SQL statement:
alter table public_partner drop constraint (select distinct unique_index_name from informa
tion_schema.constraints where table_name='PUBLIC_PARTNER' and column_list='INFO') [42001-1
60]

应如何正确删除此约束?

How this constraint should be correctly removed?

顺便说一句:

sql> (select unique_index_name from information_schema.constraints where table_name='PUBLI
C_PARTNER' and column_list='INFO');
UNIQUE_INDEX_NAME
CONSTRAINT_F574_INDEX_9
(1 row, 0 ms)

似乎返回了正确的输出。

seems to return a correct output.

推荐答案

在SQL语言中,标识符名称不能是表达式。您需要运行两个语句:

In the SQL language, identifier names can't be expressions. You need to run two statements:

select distinct constraint_name from information_schema.constraints 
where table_name='PUBLIC_PARTNER' and column_list='INFO'

,然后获取标识符名称,并运行语句

and then get the identifier name, and run the statement

ALTER TABLE PUBLIC_PARTNER DROP CONSTRAINT <xxx>

这篇关于在H2中删除列的唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆