sql – 在H2中删除列的唯一约束

前端之家收集整理的这篇文章主要介绍了sql – 在H2中删除列的唯一约束前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试为h2中的列删除唯一约束,以前创建为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');

但没有成功(如下):

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]

如何正确删除此约束?

顺便说说:

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)

似乎返回正确的输出.

解决方法

sql语言中,标识符名称不能是表达式.您需要运行两个语句:
select distinct constraint_name from information_schema.constraints 
where table_name='PUBLIC_PARTNER' and column_list='INFO'

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

ALTER TABLE PUBLIC_PARTNER DROP CONSTRAINT <xxx>

猜你在找的MsSQL相关文章