Jayesh Bhoot's Ghost Town

Name your SQL constraints

Posted on in

I learnt the hard way, while trying to amend the structure of a database instantiated at more than one place, that its best to explicitly name the SQL constraints like a foreign key.

Trying to adjust a foreign key constraint by referring it to its implicit name felt like holding on to a falling person just with their shoe. I could never be sure that the implicit name would be identical across different instances of the database.

Also, in MySQl at least, there was no foolproof way to dynamically query for the implicit name.