Change order of column in SQL 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Naveen Kumar Srivastava
    New Member
    • Sep 2007
    • 17

    Change order of column in SQL 2005

    Hi to all

    I have a table having three column. I add one column at run time and client requirement is that this added column should be first column.

    How i can make this as a first column

    Thanks to all
  • vksingh24
    New Member
    • Dec 2007
    • 21

    #2
    Originally posted by Naveen Kumar Srivastava
    Hi to all

    I have a table having three column. I add one column at run time and client requirement is that this added column should be first column.

    How i can make this as a first column

    Thanks to all

    I am not sure but you can use the column name which you have added at run time as the first column in your SELECT Statement

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Create a function or a view. Or simply, on your extract, do a

      Code:
      SELECT Col4, Col1, Col2, Col3 from YourTable
      -- CK

      Comment

      • Naveen Kumar Srivastava
        New Member
        • Sep 2007
        • 17

        #4
        Originally posted by vksingh24
        I am not sure but you can use the column name which you have added at run time as the first column in your SELECT Statement
        Thanks for reply

        But actually the problem is that
        I have a table which contain identity column
        When i delete some data i.e. row from table then sedquence will break
        (1,2,3,7,8) Identity column have these value we have to make this like (1,2,3,4,5)

        How i can

        Comment

        • Naveen Kumar Srivastava
          New Member
          • Sep 2007
          • 17

          #5
          Originally posted by ck9663
          Create a function or a view. Or simply, on your extract, do a

          Code:
          SELECT Col4, Col1, Col2, Col3 from YourTable
          -- CK


          Thanls foe reply

          I am not creating table at run time i have to update the idemtity column at run time

          Comment

          • ck9663
            Recognized Expert Specialist
            • Jun 2007
            • 2878

            #6
            You can't. Identity columns are read-only. I think you can reset it, but if you use that as PK/FK, your table relationship will be affected.

            -- CK

            Comment

            • Delerna
              Recognized Expert Top Contributor
              • Jan 2008
              • 1134

              #7
              I don't have SQL 2005 so I don't know the correct syntax but Sql server 2005 has a function that returns the row number.
              So you could use that to achieve what you need.
              In your example the identity field will be 1,2,3,7,8
              but the field that returns the row number will be 1,2,3,4,5
              You will obviously need to sort the records by the indentity field so that the row numbers will be correct.

              Comment

              Working...