sql-server - 如何在 Python 中的 Pymmsql 中创建和重新创建索引?
问题描述
我正在尝试在 Python 中创建和重新创建索引,但是当我使用它时出现错误。
Error:
File "src\pymssql.pyx", line 468, in pymssql.Cursor.execute
pymssql.OperationalError: (7999, b"Could not find any index named 'Micros' for table
'payrolldata'.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages
from the SQL Server\n")
代码:
with pymssql.connect ("127.0.0.1","arcdbadmin", "@rcT3chn010g13$","Micros") as myDbConn:
with myDbConn.cursor(as_dict=True) as cursor:
cursor.execute("""create index Micros on payrolldata(stono,payrollid,busdate) WITH(DROP_EXISTING = ON);""")
myDbConn.commit()
解决方案
WITH(DROP_EXISTING = ON)
除非索引已经存在,否则您不能使用。
如果先存在,您可以删除索引:
drop index if exists Micros on payrolldata
如果你愿意,首先。在旧版本上,您可以运行
if exists (select * from sys.indexes where name = 'Micros' and object_id('payrolldata') = object_id)
begin
drop index micros on payrolldata
end
推荐阅读
- c# - 应用依赖注入时如何使用子类
- kotlin - Kotlin 中两种初始 MutableLiveData 方式有什么不同?
- awk - awk if 0 除以 x 输出 0
- sql - 如何在 Power BI 中加入 2 个表,条件涉及第 3 个表
- linux - 使用 UNIX 命令行工具将 JSON 拆分为多行
- c# - 窗口大小更改时如何处理窗口内的 UserControl
- amazon-web-services - 在 AWS 中,是整个 VPC 获得一个 DNS 服务器还是 VPC 中的每个子网都获得一个 DNS 服务器?
- mysql - MySQL w/通过单个交叉引用表进行多个关联
- asp.net - 例外:无法创建 ActiveX 组件
- c# - .NET Core - 使用具有专用身份验证 API 的多个身份验证方案