Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to create custom domain / data type and associate some trigger with it, for example hash password?

I will have for example password domain and if I set some value to this column, it will automatically hash that, so I don't have to create trigger for each table with password column

share|improve this question
up vote 1 down vote accepted

You cannot do that.

As the documentation says:

CREATE TRIGGER creates a new trigger. The trigger will be associated with the specified table or view

This clearly excludes types and domains. (Very logically: triggers are normally fired upon changing something - here you want to change a column, not the type.)

You should instead use a stored procedure to take care of your password column(s). And personally I think the less places password are stored at, the better.

share|improve this answer
I agree. in fact, storing a password at all is a very dangerous pasttime. Better to store only the salted hash of the password since it is almost impossible to reverse engineer a salted hash. – Max Vernon Nov 20 '12 at 18:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.