• 注册
    • 查看作者
    • PostgreSQL 删除check约束的实现

        

        这篇文章主要介绍了PostgreSQL 删除check约束的实现,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧。

        删除check约束:

        1.\d table_name 查找约束名称

        \d dm_alarms_fct_20170613 dm_alarms_fct_20170613_dm_transct_date_key_check

        2.alter table .. drop constraint ..

        1ALTER TABLE dm_alarms_fct_20170613 Drop constraint dm_alarms_fct_20170613_dm_transct_date_key_check;

        补充:PostgreSQL查询约束和创建删除约束

        查询约束constraint

        SELECT
      tc.constraint_name, tc.table_name, kcu.column_name,
      ccu.table_name AS foreign_table_name,
      ccu.column_name AS foreign_column_name,
      tc.is_deferrable,tc.initially_deferred
      FROM
      information_schema.table_constraints AS tc
      JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
      JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
      WHERE constraint_type = UNIQUE AND tc.table_name = table_name;

        constraint_type有四种:

        UNIQUE、PRIMARY KEY、CHECK、FOREIGN KEY, 通过修改上边sql语句的table_name和constraint_type来进行相应的查询。

        添加约束

        1ALTER TABLE table_name ADD CONSTRAINT uk_users_name1 UNIQUE (NAME);

        删除约束

        1alter table table_name drop constraint if EXISTS uk_users_name1;

        文章来源:脚本之家

        来源地址:https://www.jb51.net/article/205217.htm

        

    • 0
    • 0
    • 0
    • 8
    • 请登录之后再进行评论

      登录
    • 单栏布局 侧栏位置: