在 SQL Server 中的其他两列之间添加列
您是否可以向表中添加一列,并将其插入 SQL Server 中的两个现有列之间,而无需删除并重新创建该表?
Can you add a column to a table inserting it in between two existing columns in SQL Server without dropping and re-creating the table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
中等长度的答案,是的(ish),但它很丑陋,你可能不想这样做。
请注意:此代码创建一个物理表
Mediumly long answer, yes (ish) but it's ugly and you probably wouldn't want to do it.
please note: this code creates a physical table
简单的答案是否定的。列顺序对您来说很重要,有什么原因吗?
The simple answer is no. Is there a reason why column order is important to you?
是的,您可以在此处添加您关心的查询:
Yes you can add here is the query for your concern:
看一下这个链接:
http ://www.bobsgear.com/display/ts/Adding+Column+After+Another+Column+-+SQL+Server+2005
如您所见,答案是:
'不移动就不可能将数据保存到临时表中”,
这就是 SQL Server Management Studio 实际执行的操作。
Take a look at this link:
http://www.bobsgear.com/display/ts/Adding+Column+After+Another+Column+-+SQL+Server+2005
As you can see, the answer is:
'not possible without moving data to a temp table'
which is what the SQL Server Management Studio actually does.
是的。您可以在设计模式下拖放它,或者在编辑表模式下复制并粘贴它
以响应评论,是的,这是通过 UI 使用 SQL Server Management Studio,在幕后,它正在执行删除/重新创建您的操作。我们试图避免,所以不,如果没有服务器为您做这件事,您就无法做到这一点。
yes. You can drag and drop it in design mode, or copy and paste it in edit table mode
in response to comments, yes, this is with SQL Server Management Studio through the UI, and under the hood, it's doing the drop/recreate you're trying to avoid, so no, you can't do it without the server doing it for you.
这在 SQL Server Management Studio (SSMS) 中是可能的。
在对象资源管理器中过滤表格,然后右键单击表格 >设计
拖动左侧突出显示的箭头来移动您的列。
This is possible in SQL Server Management Studio (SSMS).
Filter your table in Object Explorer and right click on the table > Design
Drag the arrow highlighted in the left to move your column.
首先回答,没有。
第二个答案,根据此线程 http://www.sqlteam.com/forums /topic.asp?TOPIC_ID=58912,通过 可以找到我在逻辑上对表中的列重新排序?,您可以创建该列,然后通过编辑系统表对表中的列重新排序。但它看起来非常混乱,我不相信事情不会被破坏。
First answer, no.
Second answer, according to this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=58912, found via Can I logically reorder columns in a table?, you could create the column then reorder the columns in the table by editing the system tables. But it looks incredibly messy and I would not trust that things would not break.
对于 Mysql 是 对于 SQL Server 否
此外,在两者之间添加列也不是一个好习惯,因为如果您依赖项目中的表架构,它可能会妨碍某些查询。
For Mysql yes For SQL server No
also it's not a good practice to add column in between as it can hamper some queries if you are relying on the table schema in your project.