I'm trying to rename a column name in SQL-Server from Python.
Code
def ModifeingColumnName():
try:
myconn = mysql.connector.connect(host ="localhost" , user = "root" , password = "", database = "test")
mycurs = myconn.cursor()
mycurs.execute('''EXEC SP_RENAME 'test_table.Name','First_Name','COLUMN' ''')
myconn.commit()
print('changed successfully!')
except:
print('failed!')
- my database name is
(test) - my table is
(test_table) - my column name is
(Name)
Issue
It doesn't work. It always reached the except block.
What's the problem?
I'm using SQL and here is the error when i remove the try block :
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXEC SP_RENAME 'test.Name','First_Name','COLUMN'' at line
failed!? Also, you are using amysqlmodule but using a T-SQL query, so what are you using as your database, and are you using the right module to connect to it?T-SQLsyntax to perform a table update when your backing database is MariaDB/MySQL.SP_RENAMEis Microsoft SQL Server-specific.