views:

124

answers:

1

When constraints are created they are given names that look something like this 'FK5E6B788655A1514E'.

I'm wondering if the name generation is deterministic or random. I noticed that two separate databases I was using, same schemas, ended up with the same FK names.

Does it make sense when writing an upgrade script from one version of a schema to another to make use of these constraint names?

+1  A: 

It appears that the machine-generated names are consistent. But this is not guaranteed behavior. I suspect that if MySQL had some need to change the method of generating names in some future version, they would not feel they were breaking backward compatibility by doing so.

Are you aware you can specify constraint names yourself, to bypass the automatically generated names?

create table foo (
  i int, 
  constraint `i_is_unique` unique key (i)
);
Bill Karwin
Yes I'm aware... but! other than in an upgrade, I'm not touching the schema manually... I'm letting the tables generate automatically when I deploy my JavaEE application.
carrier