Friday, 9 August 2013

Change Column Name

Change Column Name

I have a table called xro_zips_import, which is located on a sql server
database. It contain's millions of row of data. I have a column named
'City' and 'CityAliasName' within the table. I need to drop the city
column and change the CityAliasName to City. I'm not sure how to use the
sp_Rename procedure correctly in Python. This is what I currently have.
conn.cursor().execute('ALTER TABLE xro_zips_import DROP COLUMN City')
conn.commit()
conn.cursor().execute("{EXEC sp_RENAME} (?,?,?),
('xro_zips_import.CityAliasName', 'City', 'COLUMN')")
conn.commit()
This is the error that I receive after the execution of sp_RENAME
Traceback (most recent call last): File
"Z:\Projects\ZipCodes\ftpUpdate.py", line 274, in
conn.cursor().execute("{EXEC sp_RENAME} (?,?,?),
'xro_zips_import.CityAliasName', 'City', 'COLUMN'") ProgrammingError:
('42000', '[42000] [Microsoft][SQL Server Native Client 10.0]Syntax error,
permission violation, or other nonspecific error (0) (SQLExecDirectW)')

No comments:

Post a Comment