如何在sql 2005中的列之间添加列 [英] how to add column in between columns in sql 2005

查看:83
本文介绍了如何在sql 2005中的列之间添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql 2005的列之间添加新列

how to add new column in between columns in sql 2005

推荐答案

不能在两个现有列之间插入新列使用查询.
使用GUI ,您可以在表设计中选择列行,然后选择插入列" 选项.

如果不创建新表,则不能以编程方式(以一种安全的方式)执行此操作.没有另一种方法可以在现有列之间的"SQL Server表"中插入列-您需要构建一个临时表并重建旧表.

提交重新排序时,企业管理器的作用是创建一个新表,移动数据,然后删除旧表并将新表重命名为现有名称.

如果希望按特定的顺序/分组排列而不改变其物理顺序,则可以创建一个可以随心所欲的视图.

如果您只是想将列添加到现有表中,则可以通过以下方式进行操作:
You cannot insert a new column between two existing columns using a query.
Using GUI, you can by selecting the column row in table-design and choosing insert a column option.

You can not do this programatically (in a safe way that is) without creating a new table. There isn''t another way to insert a column in a SQL Server table "in between" existing columns - you need to build a temp table and rebuild the old table.

What Enterprise Manager does when you commit a reordering is to create a new table, move the data and then delete the old table and rename the new table to the existing name.

If you want your columns in a particular order/grouping without altering their physical order, you can create a view which can be whatever you desire.

If you simply wants to add column to existing table then, you can do it this way:
ALTER TABLE MyTable
ADD MyColumn DATETIME DEFAULT GETDATE() WITH VALUES NOT NULL


参考:
http://msdn.microsoft.com/en-us/library/aa977261 (v = vs.71).aspx [ http://msdn.microsoft.com/en-us/library/ms190273.aspx [ ^ ]


Refer:
http://msdn.microsoft.com/en-us/library/aa977261(v=vs.71).aspx[^]
http://msdn.microsoft.com/en-us/library/ms190273.aspx[^]


只需右键单击表名并进行修改.您将看到表列.右键单击要添加新列的列,然后选择插入列".
Just right click on your table name and go to modify.You will see the table columns.Right click on column before which you want to add new column and select Insert Column And you are done..




试试这个:
Hi,

Try this:
--Here RiskLocationID, Code, Description is the columns from your table and 'Test'
--is a new column added dynamicaly.
select RiskLocationID, 1 as 'Test', Code, Description from sdfWarnt




--Amit




--Amit


这篇关于如何在sql 2005中的列之间添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆