check_relation.py
821 Bytes
# -*- coding: utf-8 -*-
import pyodbc
conn_str = 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.168.1.91,1433;DATABASE=wms4_global;UID=sa;PWD=HHrobot123.'
conn = pyodbc.connect(conn_str)
cursor = conn.cursor()
# 查看 task_detail 表结构
print("=" * 80)
print("【查看 task_detail 表结构】")
print("=" * 80)
cursor.execute("""
SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'task_detail'
ORDER BY ORDINAL_POSITION
""")
for row in cursor.fetchall():
print(f" {row[0]}: {row[1]}")
print("\n" + "=" * 80)
print("【查看 task_detail 示例】")
print("=" * 80)
cursor.execute("SELECT TOP 3 * FROM task_detail")
cols = [desc[0] for desc in cursor.description]
print(f" 字段: {cols}")
for row in cursor.fetchall():
print(f" {row}")
conn.close()