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