简体   繁体   English

在python中使用pyodbc/turbodc从现有表创建SQL表

[英]create SQL table from existing table using pyodbc/turbodc in python

I would like to create a SQL table from an existing table.我想从现有表创建一个 SQL 表。 I'm using the turbodbc module (which is very similar to pyodbc).我正在使用 turbodbc 模块(与 pyodbc 非常相似)。

# connect to database
conn = turbodbc.connect(connection_string="my_connection_string")
cursor = conn.cursor()
# execute SQL code
cursor.execute((" create table Test_Puts as"
                " select * from OptionValue"
                " where call_put = 'P'"))

However, I get the error message:但是,我收到错误消息:

ODBC error
state: 42000
native error code: 156
message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'select'.

Try to use this syntax:尝试使用以下语法:

select * into Test_Puts from  OptionValue where call_put = 'P'

So, instead of this:所以,而不是这个:

" create table Test_Puts as"
" select * from OptionValue"
" where call_put = 'P'"

use this:用这个:

" select * into Test_Puts"
" from  OptionValue"
" where call_put = 'P'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python SQL Server - 从现有表中的值创建表 - Python SQL Server - Create Table from Values from an existing Table 使用 pyodbc - Python 更新 Microsoft SQL 表上的字段 - Updating fields on a Microsoft SQL Table using pyodbc - Python 无法在导入pyodbc的python中创建易失性表 - Volatile table can not be create in python importing pyodbc 使用python在现有的SQL Server表中附加来自excel的数据 - Appending data from excel in existing SQL Server table using python 使用pyodbc将日期时间插入MS SQL表 - Inserting datetime into a MS SQL table using pyodbc 使用表类型从pyodbc没有结果 - No Results from pyodbc using table type 在 Python 中使用 PYODBC 使用以表为参数的存储过程更新 SQL Server 数据库 - Update SQL Server database using stored procedure with table as paramater using PYODBC in Python 如何在运行时使用带占位符的绑定变量更新 SQL 服务器中的表? 在 python 中使用 pyodbc 模块? - How to update a table in SQL Server during runtime using bind variable with a placeholder like '?' in python using pyodbc module? python Pyodbc,无法在表中创建一个名为“ Date”的字段 - python Pyodbc, cant create a field named “Date” in the table 当从 pyodbc Python 调用 SQL 服务器 SP 时,表被锁定 - Table get locked when called an SQL Server SP from pyodbc Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM