問題描述
我正在使用 SQL Server 2008 R2,我希望將新列添加到表中列順序中的特定位置,而不是最后.我希望避免重新創(chuàng)建表.如何在不重新創(chuàng)建表格的情況下執(zhí)行此操作?
I am using SQL Server 2008 R2 and I wish to add a new column into a specific spot in the column order in a table and not at the end. I wish to avoid having to recreate the table. How do I do this without recreating the table?
即
Table: Bob
==========
Col1
Col2
添加新列.
Table: Bob
==========
Col1
NewCol
Col2
推薦答案
你不能.列始終添加在列列表的末尾.更改順序的唯一方法是從頭開始重新創(chuàng)建表.
You cannot. Column are always added at the end of the column list. The only way to change the order is to recreate the table from scratch.
話雖如此,列的實(shí)際物理順序或列定義的邏輯順序?qū)δ鷣碚f永遠(yuǎn)無關(guān)緊要.如果您對列順序有依賴性,則您的代碼已損壞.如果您希望從列順序中獲得性能提升,那這些都是誤區(qū).
That being said, it should never ever matter to you what is the actual physical order of the columns, nor the logical order of column definitions. If you have dependencies on column order, your code is broken. If you expect performance gains from column order, those are myths.
這篇關(guān)于SQL Server 2008 R2 將列添加到特定位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!