0

import pyodbc 
connection_string = ("DRIVER={##########};"
                     "SERVER=############;"
                     "DATEBASE=#############"
                     "UID=############;"
                     "PWD=#########"
                     )

cnxn = pyodbc.connect(connection_string)
cursor = cnxn.cursor()
query = "sp_help '<tablename>';"
cursor.execute(query)
result1= cursor.fetchone()
print (result1)
cnxn.close()

When I execute the above from python I get this as output:

('XX_SAMPLE', 'dbo', 'user table', datetime.datetime(2022, 2, 15, 10, 43, 57, 610000))

but when I execute the same query from the SSMS I get :

enter image description here


so, is there any way to store rest all data that is displayed in SSMS if I run it from python

Charlieface
  • 52,284
  • 6
  • 19
  • 43
  • 3
    `sp_help` returns multiple result sets. You're only pulling the first one. Have a look at this question and see if that helps: https://stackoverflow.com/questions/273203/access-second-result-set-of-stored-procedure-with-sql-or-other-work-around-pyth – squillman Feb 22 '22 at 16:37
  • You could write your own query utilizing `sys.tables` and `sys.columns` etc. There are many tutorials online – Charlieface Feb 22 '22 at 22:39

0 Answers0