在 Python 中删除索引时出错
Errors Dropping a Index in Python
我有这些 pymmsql 索引错误我在我的代码中创建了 3 个索引,我想删除它们但它们不会删除我收到这些错误
代码:
DbConnect = 'Micros'
myDbConn = pymssql.connect(*******,"******", "*******",DbConnect)
cursor = myDbConn.cursor()
cursor.execute("""DROP INDEX [IF EXISTS]
Micros ON payrolldata;""")
cursor.execute("""DROP INDEX [IF EXISTS]
MainSort ON s20data,StoreSort ON s20data;""")
myDbConn.commit()
错误:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Python37-32\SqlVersionpr_import.py", line 840, in proceed
Micros ON payrolldata;""")
File "src\pymssql.pyx", line 465, in pymssql.Cursor.execute
pymssql.ProgrammingError: (102, b"Incorrect syntax near 'Micros'.DB-Lib error message 20018, severity
15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
正确的语法应该是。
DROP INDEX IF EXISTS IndexName;
DROP INDEX IndexName;
方括号表示参数或语句的一部分是可选的。
请参阅文档
https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-index-transact-sql?view=sql-server-ver15
我有这些 pymmsql 索引错误我在我的代码中创建了 3 个索引,我想删除它们但它们不会删除我收到这些错误 代码:
DbConnect = 'Micros'
myDbConn = pymssql.connect(*******,"******", "*******",DbConnect)
cursor = myDbConn.cursor()
cursor.execute("""DROP INDEX [IF EXISTS]
Micros ON payrolldata;""")
cursor.execute("""DROP INDEX [IF EXISTS]
MainSort ON s20data,StoreSort ON s20data;""")
myDbConn.commit()
错误:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Python37-32\SqlVersionpr_import.py", line 840, in proceed
Micros ON payrolldata;""")
File "src\pymssql.pyx", line 465, in pymssql.Cursor.execute
pymssql.ProgrammingError: (102, b"Incorrect syntax near 'Micros'.DB-Lib error message 20018, severity
15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
正确的语法应该是。
DROP INDEX IF EXISTS IndexName;
DROP INDEX IndexName;
方括号表示参数或语句的一部分是可选的。 请参阅文档
https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-index-transact-sql?view=sql-server-ver15