0

we have a existing table in SQL Server DB. we need to add a column to the existing table. here is the existing columns,

col1, col2, col5, col6

here is the columns which has to be added to the table,

col1, col2, col3, col4, col5, col6 - in this sequence we need to add in SQL Server.

can you please help me out in this

  • 1
    AFAIK, SQL Server can only add new columns at the end. – jarlh Jan 14 '22 at 09:16
  • 1
    The order of the columns within the table shouldn't matter anyway. You can control the order of the column in the `SELECT` if you need to; there is no reason to `DROP` and re`CREATE` a table just because you want a column to be in a different ordinal position, – Thom A Jan 14 '22 at 09:21
  • @jarlh Actually, if i understand the question correctly, in SQL Server Management you can create a new column, via the design view, and drag the column up to the position you want – JamesS Jan 14 '22 at 10:09
  • @JamesS, yes it can. But I don't know how it handles different types of dependencies, like foreign keys, since it - as I understand it - drops columns and then adds them after the new column. – jarlh Jan 14 '22 at 11:30
  • @James Using the SSMS gui, you have the option of saving any change you make to a script. If you do that, you can see the SQL that SSMS generates to accomplish that. To add a column "in the middle", the GUI will generate a script that completely recreates the table which is the only way to accomplish this. – SMor Jan 14 '22 at 12:21

0 Answers0