'Fetch the id for schema.table_name.
Several reflection methods require the table id.  The idea for using
this method is that it can be fetched one time and cached for
subsequent calls.'

def get_table_id(self, connection, table_name, schema=None, **kw):

    table_id = None
    if (schema is None):
        schema = self.default_schema_name
    TABLEID_SQL = text("\n                                        SELECT    o.id    AS    id\n                                        FROM    sysobjects    o    JOIN    sysusers    u    ON    o.uid=u.uid\n                                        WHERE    u.name    =    :schema_name\n                                                        AND    o.name    =    :table_name\n                                                        AND    o.type    in    ('U',    'V')\n                                ")
    if util.py2k:
        if isinstance(schema, unicode):
            schema = schema.encode('ascii')
        if isinstance(table_name, unicode):
            table_name = table_name.encode('ascii')
    result = connection.execute(TABLEID_SQL, schema_name=schema, table_name=table_name)
    table_id = result.scalar()
    if (table_id is None):
        raise exc.NoSuchTableError(table_name)
    return table_id
