I am struggling with a problem and I hope someone could help a brother out.
I tried INSERT INTO but got an error message: Error Code: 3819. Check constraint ‘inventory_chk_1’ is violated.
To troubleshoot the issue, i want to examine the specific check constraint named "inventory_chk_1" to understand the condition it enforces and I tried this:
SELECT constraint_name, check_clause
FROM information_schema.check_constraints
WHERE constraint_schema = 'book_shop'
AND table_name = 'inventory'
AND constraint_name = 'inventory_chk_1';
I get yet another error: Unknown column ‘table_name’ in ‘where clause’.
Then i tried this:
SELECT constraint_name, check_clause
FROM information_schema.check_constraints
WHERE constraint_schema = 'book_shop'
AND table_name = 'inventory'
AND constraint_type = 'CHECK'
AND constraint_name = 'inventory_chk_1';
and so on and on..
Can someone point what my mistake might be?
Much appreciated!
I tried multiple modifications of the code but none worked. I want to solve the issue!
2
Answers
Take a look at the docs for the
Information_schema.Check_Constraints
table. I don’t know about you, but I don’t see anyTable_Name
column. Instead, constraint names must be unique across an entire schema. And since you’re already looking up the constraint by schema, you can simply remove thetable_name
predicate completely and still have confidence you’re seeing the right result.You can do:
For example:
Result: