Alter Constraints

Lets extend the concept of alter to modifying constraints.

Taking the users table example that we had earlier, lets add some constraints.

ALTER TABLE users ADD CONSTRAINT agecheck CHECK (age < 60);

This will add a constraint named agecheck with the condition that the age should be less than 60.

Now to drop the same constraint, we can execute the following statement:

ALTER TABLE users DROP CONSTRAINT agecheck;

Constraints can be of different types. As we saw earlier, it could be on the Column, on the Table or it could be a Check constraint.

Now if you want to change an existing constraint, you will drop the constraint first and then follow it up with the add constraint statement. This can also be done in a single transaction that is executed instead of multiple independent statements.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin
graphql-handbook