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. Need to Add a column to the existing table

Need to Add a column to the existing table

Scheduled Pinned Locked Moved Database
questionpostgresqlhelp
5 Posts 4 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.
  • S Offline
    S Offline
    SelvaKr
    wrote on last edited by
    #1

    Hi, How can I add a new column in middle/(at any position) of the existing table? How can I do that in Postgres? Any help would be appreciated.

    Selva

    J 1 Reply Last reply
    0
    • S SelvaKr

      Hi, How can I add a new column in middle/(at any position) of the existing table? How can I do that in Postgres? Any help would be appreciated.

      Selva

      J Offline
      J Offline
      joemonvarghese
      wrote on last edited by
      #2

      hi plz make use of Sql Help hint: you can achieve this using ALTER TABLE Command ALTER TABLE TABLENAME ADD COLUMNNAME DATATYPE(SIZE) -- modified at 6:11 Tuesday 13th November, 2007

      S 1 Reply Last reply
      0
      • J joemonvarghese

        hi plz make use of Sql Help hint: you can achieve this using ALTER TABLE Command ALTER TABLE TABLENAME ADD COLUMNNAME DATATYPE(SIZE) -- modified at 6:11 Tuesday 13th November, 2007

        S Offline
        S Offline
        SelvaKr
        wrote on last edited by
        #3

        Thanks for the reply. But it will add the new column at the last. But i want it to get added at the middle. Is there any way to achieve this.

        Selva

        P J 2 Replies Last reply
        0
        • S SelvaKr

          Thanks for the reply. But it will add the new column at the last. But i want it to get added at the middle. Is there any way to achieve this.

          Selva

          P Offline
          P Offline
          Paddy Boyd
          wrote on last edited by
          #4

          Column ordering is not important within a SQL server database - why do you need to do this.

          1 Reply Last reply
          0
          • S SelvaKr

            Thanks for the reply. But it will add the new column at the last. But i want it to get added at the middle. Is there any way to achieve this.

            Selva

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            SelvaKr wrote:

            But i want it to get added at the middle. Is there any way to achieve this.

            If it was me I would start by questioning the requirement, because it suggests that someone either doesn't know how databases work and/or are using it incorrectly for some other purpose. But excluding that you would have to 1. Create temporary table. 2. Copy all of the data to the temp table. 3. Delete the original table. 4. Re-create with the new column 5. Copy all of the data back to the newly created table. 6. Delete the temp table. Obviously you will need to deal with foreign keys appropriately. And it is likely that that the database can not be active (not processing work) while this is going on.

            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