Add Column on SQL Server on Specific Place?

前端 未结 9 1617
-上瘾入骨i
-上瘾入骨i 2021-01-19 02:12

I would like to know if there\'s a way to add a column to an SQL Server table after it\'s created and in a specific position??

Thanks.

相关标签:
9条回答
  • 2021-01-19 02:18

    With Sql Server Management Studio you can open the table in design and drag and drop the column wherever you want

    0 讨论(0)
  • 2021-01-19 02:23

    The only safe way of doing that is creating a new table (with the column where you want it), migrating the data, dropping the original table, and renaming the new table to the original name.

    This is what Management Studio does for you when you insert columns.

    0 讨论(0)
  • 2021-01-19 02:28

    The safest way to do this is.

    • Create your new table with the correct column order
    • Copy the data from the old table.
    • Drop the Old Table.
    0 讨论(0)
  • 2021-01-19 02:29

    In databases table columns don't have order.

    Write proper select statement and create a view

    0 讨论(0)
  • 2021-01-19 02:33

    In addition to all the other responses, remember that you can reorder and rename columns in VIEWs. So, if you find it necessary to store the data in one format but present it in another, you can simply add the column on to the end of the table and create a single table view that reorders and renames the columns you want to show. In almost every circumstance, this view will behave exactly like the original table.

    0 讨论(0)
  • 2021-01-19 02:34

    You can do that in Management-Studio. You can examine the way this is accomplished by generating the SQL-script BEFORE saving the change. Basically it's achieved by:

    • removing all foreign keys
    • creating a new table with the added column
    • copying all data from the old into the new table
    • dropping the old table
    • renaming the new table to the old name
    • recreating all the foreign keys
    0 讨论(0)
提交回复
热议问题