数据库约束新建,查看,删除

数据库约束查看

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 = 'test';

constraint_type有四种:UNIQUE、PRIMARY KEY、CHECK、FOREIGN KEY

数据库约束新增

alter table test add CONSTRAINT unique_bill_no UNIQUE (bill_no,is_del);

数据库约束删除

alter table test drop constraint unique_bill_no

猜你喜欢

转载自blog.csdn.net/hbn1326317071/article/details/84960906