Para testar use posgres BD tenis tabela jtest (jogadores) NOTA: os comandos de atualizacao (update) violam uma constraint definida anteriormente e nao sao executados alter table jtest add constraint chk_j1 check (vits > tit_s) 0 row(s) affected by your update/insert/delete command update jtest set vits =53 where numj = 29 ERROR: new row for relation "jtest" violates check constraint "chk_j1" ---------------------------------------------------------------------- alter table jtest add constraint chk_j2 check (ano_p -ano_n > 15 and ano_n >66) ERROR: check constraint "chk_j2" is violated by some row ------------------------------------------------------------- alter table jtest drop constraint chk_j2 alter table jtest add constraint chk_j2 check (ano_p -ano_n > 15 and ano_n >= 66) 0 row(s) affected by your update/insert/delete command update jtest set ano_p= 84 where numj = 29 ERROR: new row for relation "jtest" violates check constraint "chk_j2" ---------------------------------------------------------------------- -- Pesquisa no Google: "Postgres find constraint names". Achei: SELECT conname, contype FROM pg_catalog.pg_constraint c JOIN pg_class t ON t.oid = c.conrelid WHERE t.relname ='jtest' conname contype chk1 c chk_j2 c 2 rows returned by your query in 0.0 secs ----------------------------------------------------------------- numj nome pnome pais ano_n ano_p cid_n cid_res tit_s tit_d vits derrs natp -------------------------------------------------------------------- Constraint como "expressao regular": alter table jtest add constraint chk_j3 check (pais ~ '[A-Z]{3}') -- exatamente 3 letras maiusculas updOBte jtest set pais = 'swe' where numj = 19 ERROR: new row for relation "jtest" violates check constraint "chk_j3" ------------------------------------------------------------- update jtest set pais = 'SWe' where numj = 19 ERROR: new row for relation "jtest" violates check constraint "chk_j3 -------------------------------------------------------------------- update jtest set pais = 'BRAS' where numj = 19 ERROR: value too long for type character(3) ------------------------------------------------------------- update jtest set pais = 'BR' where numj = 16 ERROR: new row for relation "jtest" violates check constraint "chk_j3" ---------------------------------------------------------------------- ******************************************************************* Pesquisa no Google: "Postgres find constraint names". Achei: SELECT conname, contype FROM pg_catalog.pg_constraint c JOIN pg_class t ON t.oid = c.conrelid WHERE t.relname ='jtest' ***************************************************************** alter table jtest add constraint chk_email_ check (email ~ '^[a-z]+\.?[a-z]+@([a-z]+\.[a-z]+\.[a-z]+)|([a-z]+\.[a-z]+)$') update jtest set email = 'stefan\.edberg@ic.unicamp.swe' where numj = 19 select numj,pnome, nome,pais,email from jtest order by numj *************************************************************** -- nenhum funcionario pode ter salario superior ao do chefe alter table funcionarios add constraint chk_sal check (sal <= (select f1.sal from funcionarios f1 where f1.numf = funcionarios.numc)) ERROR: cannot use subquery in check constraint ************************************************