对于Access ODBC,我们可以通过
.statisticspyodbc
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'}


