'Find the constraints that apply to a column, needed when deleting. Defaults not included.
This is more general than the parent _constraints_affecting_columns, as on MSSQL this
includes PK and FK constraints.'

def _find_constraints_for_column(self, table_name, name, just_names=True):

    sql = "\n                                    SELECT    CC.[CONSTRAINT_NAME]\n                                                        ,TC.[CONSTRAINT_TYPE]\n                                                        ,CHK.[CHECK_CLAUSE]\n                                                        ,RFD.TABLE_SCHEMA\n                                                        ,RFD.TABLE_NAME\n                                                        ,RFD.COLUMN_NAME\n                                                        --    used    for    normalized    names\n                                                        ,CC.TABLE_NAME\n                                                        ,CC.COLUMN_NAME\n                                        FROM    [INFORMATION_SCHEMA].[TABLE_CONSTRAINTS]    TC\n                                        JOIN    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE    CC\n                                                            ON    TC.CONSTRAINT_CATALOG    =    CC.CONSTRAINT_CATALOG    \n                                                        AND    TC.CONSTRAINT_SCHEMA    =    CC.CONSTRAINT_SCHEMA\n                                                        AND    TC.CONSTRAINT_NAME    =    CC.CONSTRAINT_NAME\n                                        LEFT    JOIN    INFORMATION_SCHEMA.CHECK_CONSTRAINTS    CHK\n                                                            ON    CHK.CONSTRAINT_CATALOG    =    CC.CONSTRAINT_CATALOG\n                                                        AND    CHK.CONSTRAINT_SCHEMA    =    CC.CONSTRAINT_SCHEMA\n                                                        AND    CHK.CONSTRAINT_NAME    =    CC.CONSTRAINT_NAME\n                                                        AND    'CHECK'    =    TC.CONSTRAINT_TYPE\n                                        LEFT    JOIN    INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS    REF\n                                                            ON    REF.CONSTRAINT_CATALOG    =    CC.CONSTRAINT_CATALOG\n                                                        AND    REF.CONSTRAINT_SCHEMA    =    CC.CONSTRAINT_SCHEMA\n                                                        AND    REF.CONSTRAINT_NAME    =    CC.CONSTRAINT_NAME\n                                                        AND    'FOREIGN    KEY'    =    TC.CONSTRAINT_TYPE\n                                        LEFT    JOIN    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE    RFD\n                                                            ON    RFD.CONSTRAINT_CATALOG    =    REF.UNIQUE_CONSTRAINT_CATALOG\n                                                        AND    RFD.CONSTRAINT_SCHEMA    =    REF.UNIQUE_CONSTRAINT_SCHEMA\n                                                        AND    RFD.CONSTRAINT_NAME    =    REF.UNIQUE_CONSTRAINT_NAME\n                                        WHERE    CC.CONSTRAINT_CATALOG    =    CC.TABLE_CATALOG\n                                                AND    CC.CONSTRAINT_SCHEMA    =    CC.TABLE_SCHEMA\n                                                AND    CC.TABLE_CATALOG    =    %s\n                                                AND    CC.TABLE_SCHEMA    =    %s\n                                                AND    CC.TABLE_NAME    =    %s\n                                                AND    CC.COLUMN_NAME    =    %s    \n                                "
    db_name = self._get_setting('name')
    schema_name = self._get_schema_name()
    table = self.execute(sql, [db_name, schema_name, table_name, name])
    if just_names:
        return [r[0] for r in table]
    all = {}
    for r in table:
        (cons_name, type) = r[:2]
        if ((type == 'PRIMARY    KEY') or (type == 'UNIQUE')):
            cons = all.setdefault(cons_name, (type, []))
            sql = '\n                                                                SELECT    COLUMN_NAME\n                                                                FROM    INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE    RFD\n                                                                WHERE    RFD.CONSTRAINT_CATALOG    =    %s\n                                                                        AND    RFD.CONSTRAINT_SCHEMA    =    %s\n                                                                        AND    RFD.TABLE_NAME    =    %s\n                                                                        AND    RFD.CONSTRAINT_NAME    =    %s\n                                                                '
            columns = self.execute(sql, [db_name, schema_name, table_name, cons_name])
            cons[1].extend((col for (col,) in columns))
        elif (type == 'CHECK'):
            cons = (type, r[2])
        elif (type == 'FOREIGN    KEY'):
            if (cons_name in all):
                raise NotImplementedError('Multiple-column    foreign    keys    are    not    supported')
            else:
                cons = (type, r[3:6])
        else:
            raise NotImplementedError(("Don't    know    how    to    handle    constraints    of    type    " + type))
        all[cons_name] = cons
    return all
