`
xiagu1
  • 浏览: 47482 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

获取数据库表中所有字段名称

阅读更多

最近在用pymssql读sqlserver库里面的数据,数据库是从一堆原始数据整理以后入库的,刚开始别人给了个字段名称,看了以后发现似乎原始数据中的某些项目没有入库,刚好没找到具体负责的人。于是想知道是否能查询获取表中所有的字段名称。查了一下,原来很简单。

#! /usr/bin/env python
#coding=utf-8
import pymssql as sqlite1
# 连接数据库
try:
    cx = sqlite1.connect(host='172.1.1.1',user='uu',password='pp',database='einfo')
    print "connect ok"
except Exception, e:
    print e
    print "erro"
    sys.exit()
# 获取cursor对象来进行操作
cu = cx.cursor()
sql = "select * from tabTimeData where StationNum=57083 and ObservTimes>2010031908"
print sql
cu.execute(sql)
for i in cu.description:
    print i
cu.close()
cx.close()

 上述针对sqlserver,其他的数据库应该也可以。

0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics