0

I don't want to alter table for constraint if constraints already exists. Just ignore it

alter table test.student add constraint student_name_key unique (student_name);

In My case constraint names are present like below, not sure which is of which one.

enter image description here

Note: I use below one, still not working

ALTER TABLE test.student add CONSTRAINT IF not EXISTS student_name_key ;

PAA
  • 1
  • 46
  • 174
  • 282
  • @TimBiegeleisen - Yes I saw this link already, I dont want to drop constraint, because almost I have 120 constraints on all tables. I just simply want to ignore it, if it doesn't present – PAA Jul 10 '19 at 08:27
  • The code in the [accepted answer](https://stackoverflow.com/a/6804058/330315) of the duplicate does not drop the constraint. Plus there is [another answer](https://stackoverflow.com/a/45232288/330315) that also deals with that problem. –  Jul 10 '19 at 08:29
  • Unrelated, but all your questions around "do something if it doesn't exists" _could_ indicate the way you are deploying your database changes can be improved. You might want to check out tools like [Liquibase](http://www.liquibase.org/) or [Flyway](https://flywaydb.org/) to help you deploy database changes in a controlled manner –  Jul 10 '19 at 08:31
  • @a_horse_with_no_name - Thanks for nice suggestions. Could you please guide for above update? – PAA Jul 10 '19 at 09:15

0 Answers0