当我尝试使用cursor.primaryKeys("tablename")时会发生异常:
cursor.primaryKeys("tablename")
Error: ('IM001', '[IM001] [Microsoft][ODBC Driver Manager] Driver does not support this function (0) (SQLPrimaryKeys)')
list(cursor.columns(table='tablename')) 也不显示主键。
list(cursor.columns(table='tablename'))
对于Access ODBC,我们可以通过.statisticspyodbccursor对象的方法获取“主键”列:
.statistics
cursor
crsr = conn.cursor() table_name = 'MyTable' # dict comprehension: {ordinal_position: col_name} pk_cols = {row[7]: row[8] for row in crsr.statistics(table_name) if row[5]=='PrimaryKey'} print(pk_cols) # e.g., {1: 'InvID', 2: 'LineItem'}