server新增表字段 sql,如何在sql server中的表中的特定位置添加新列

在SQL Server中,由于表的列没有明确的顺序,因此直接添加新列会将其添加到末尾。但可以利用Information_Schema.Columns表的ORDINAL_POSITION字段重新排列列顺序。首先通过ALTER TABLE添加新列,然后更新新列和原有列的ORDINAL_POSITION,将新列移到期望的位置。虽然MSDN指出这不能直接通过T-SQL完成,但可以通过SQL Management Studio实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I have Table A with 5 columns:

TableA

--

Name

Tel

Email

Address

I want to add a new column (mobile) in between Tel & Email:

TableA

--

Name

Tel

Mobile

Email

Address

If I use

ALTER TABLE TableA

ADD COLUMN Mobile INT NOT NULL

the mobile column is added to the end of the table.

Is there a way to achieve this without dropping the table and moving data to a new table?

解决方案The table is a set of sets in relational model. As there is no explicit order between the rows, there is no explicit order between the columns either. But you can reorder them during projection by specifying the columns you need instead of using *.

But of course the RDBMS, SQL server in your case is still using some ordering. You can't really add the

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值