Showing posts with label unique-constraints. Show all posts
Showing posts with label unique-constraints. Show all posts

Friday, September 23, 2016

MySQL list all foreign key and other constraint names


SELECT  TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, 
        REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME

FROM    INFORMATION_SCHEMA.KEY_COLUMN_USAGE

WHERE   REFERENCED_TABLE_SCHEMA = 'database_name'

Tuesday, October 1, 2013

Grails domain class: unique constraint for multiple columns

Suppose a simple Grails domain class:


class Account {
    String countryId;

    String userName; 
 
    String areaId;
 
    String password;

    static constraints = {
        ...???...
    }
}


It is required that user names are unique for a particular countryId and areaId, thus there must be a unique contraint on three columns. And this is the constraints:

userName(unique: ['countryId', 'areaId'])
 
You can include as many other properties in the array that make up the 
other properties that must be considered in the "unique" constraint on 
the username.