python在win10环境下使用sqlalchemy连接sql
我的sqlserver环境是
Microsoft SQL Server Management Studio 14.0.17289.0
Microsoft Analysis Services 客户端工具 14.0.1016.283
Microsoft 数据访问组件 (MDAC) 10.0.14393.0
Microsoft MSXML 3.0 6.0
Microsoft Internet Explorer 9.11.14393.0
Microsoft .NET Framework 4.0.30319.42000
操作系统 6.3.14393
连接代码
from operatorimport or_
from sqlalchemyimport create_engine,Table,MetaData
from sqlalchemy.ext.automapimport automap_base
from sqlalchemy.ext.declarativeimport declarative_base
from sqlalchemy.ormimport sessionmaker,mapper
from sqlalchemy.poolimport NullPool
engine = create_engine('mssql+pyodbc://账号:密码@数据库地址/库名?driver=SQL+Server+Native+Client+11.0',encoding='utf-8',echo=False,poolclass=NullPool)
metadata = MetaData(engine)
metadata.reflect(bind=engine)
print('获取所有表明{}'.format(metadata.tables.keys()))