【问题标题】:How to remove check constraint in mysql workbench 8.0?如何删除 mysql workbench 8.0 中的检查约束?
【发布时间】:2020-09-22 01:12:46
【问题描述】:

谁能给我命令以删除工作台中的检查约束?我使用了alter table details drop check details_chk_1;,但它不起作用。它在 drop 命令中显示错误。请帮忙

【问题讨论】:

  • 请将 show create table details 的输出作为文本添加到问题中。
  • 错误是什么?

标签: mysql mysql-workbench alter-table check-constraints


【解决方案1】:

请尝试 ALTER TABLE details ALTER CHECK details_chk_1 NOT ENFORCED;

【讨论】:

    【解决方案2】:

    这在我的工作台 8.0 中工作

    alter table TABLE_NAME drop check CHECK_NAME;
    

    可以通过在列上运行任何命令来找到该名称。例如:我跑了

    alter table movies rename column Release_Year to  Year ;
    

    这给了我这个错误

    18:03:57    alter table movies rename column Release_Year to  Year  Error Code: 3959. Check constraint 'movies_chk_1' uses column 'Release_Year', hence column cannot be dropped or renamed.    0.000 sec
    

    您可以在此处使用约束的名称并将其粘贴以解决错误。 这是已解决的响应

    18:04:14    alter table movies drop check movies_chk_1  0 row(s) affected Records: 0  Duplicates: 0  Warnings: 0    0.203 sec
    
    18:10:17    alter table movies rename column Release_Year to  Year  0 row(s) affected Records: 0  Duplicates: 0  Warnings: 0    0.047 sec
    

    【讨论】:

      【解决方案3】:

      ALTER TABLE student DROP CONSTRAINT constraint_name;

      您也可以手动设置约束名称...但是如果您想检查自动设置的约束名称...然后输入以下查询 show create table table_name;

      【讨论】:

        猜你喜欢
        • 2020-09-20
        • 2013-06-27
        • 2021-08-03
        • 2015-10-08
        • 1970-01-01
        • 2023-03-13
        • 2021-11-18
        • 2011-05-18
        • 2012-12-16
        相关资源
        最近更新 更多