Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Columns renaming

Columns renaming

Scheduled Pinned Locked Moved Database
databasehelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jonhbt
    wrote on last edited by
    #1

    Hi I need to create a stored procedure that changes the column name of a column in a datatable. Can someone help please? Thanks

    J N 2 Replies Last reply
    0
    • J jonhbt

      Hi I need to create a stored procedure that changes the column name of a column in a datatable. Can someone help please? Thanks

      J Offline
      J Offline
      Jerry Hammond
      wrote on last edited by
      #2

      You might want to give more information. As it is, changing the name of a column as you have it stated would be a one time operation. Alter Column [column_name]

      "My interest is in the future because I'm going to spend the rest of my life there." - Charles F. Kettering

      1 Reply Last reply
      0
      • J jonhbt

        Hi I need to create a stored procedure that changes the column name of a column in a datatable. Can someone help please? Thanks

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        There is a stored procedure available in the System Stored Procedures in Sql Server. It is called sp_rename It accepts 3 parameters viz.

        @objname nvarchar(1035), -- up to 4-part "old" name
        @newname sysname, -- one-part new name
        @objtype varchar(13) = null -- identifying the name

        For renaming a column, execute the following

        EXEC sp_rename
        @objname= 'TABLE_NAME.OLD_COLUMN_NAME',
        @newname = 'NEW_COLUMN_NAME',
        @objtype = 'COLUMN'

        N.B.~ For your reference, the @objecttype correspond to system tables which track of the folowing type: 'column' 'database' 'index' 'object' 'userdatatype' Hope this helps Vote me :)

        Niladri Biswas

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups