Rename a Database Column

To rename the column of a custom DotNetNuke database table.

Working on a DNN module I chose to rename the column of a database table to better reflect it’s usage.

I wished to change the link column name from StaffId to PlayerId. For this simple amendment it would be easier to use the website’s DNN SQL Console page. Much simpler than logging into the server itself.

Here’s the code to be executed, it makes use of the built-in stored procedure sp_rename

EXEC sp_rename '{databaseOwner}{objectQualifier}ClubSports_Members.[StaffId]', 'PlayerId', 'COLUMN'

The code will be executed using the stored procedure sp_rename to change the StaffId column in the ClubSports_Members table to PlayerId.

{databaseOwner} and {objectQualifier} are DotNetNuke variables. These are configured in the web.config file and will be automatically replaced.

  • {databaseOwner} – allowing unique prefix for the DNN database.
  • {objectQualifier} – a prefix for SQLserver objects, usually left blank

Login to the DNN website with an super user account. In the left hand admin menu hover over the gear icon to expand the admin Settings. Click on the SQL Console option.

The window shows a drop down list for existing queries, with the option to upload a file.

Below this is a large entry box where the above code can be pasted. Paste the code and click on the blue button – Run Script.