2

I have a table in ms-access db, and I need to fetch just the column names of that table, into a list or a tuple.

If someone can suggest a query or point me to documentation on this.

Ejaz
  • 1,504
  • 3
  • 25
  • 51

1 Answers1

7

Similar to the question here, you could do something like this:

# -*- coding: utf-8 -*-
import pypyodbc
cnxn = pypyodbc.connect(
    r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};' +
    r'DBQ=C:\Users\Public\Database1.accdb')
crsr = cnxn.cursor()
res = crsr.execute("SELECT * FROM Clients WHERE 1=0")
columnList = [tuple[0] for tuple in res.description]
crsr.close()
cnxn.close()
print(columnList)
Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418