在表中添加一列指定的位置.. [英] add a column specified location in Table..

查看:79
本文介绍了在表中添加一列指定的位置..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生,

i有一个表emp,它有三个字段,一个是empno int,第二个是

ename varchar(20)。

,最后是薪水,


emp


empno ename薪水

------- ---- ------------ ---------

1000 suresh 10000

1001 ramesh 20000
i想要在列''ename''

和''salary''之间添加一个列名是''doj varchar'。

i不想要只添加一个,我只想在

''ename''和''salary'之间添加一个列。

给我一些例子

谢谢你先生

hello sir,
i have a table emp ,it has three fields one is empno int ,second is
ename varchar(20).
and last is salary ,

emp

empno ename salary
----------- ------------ ---------
1000 suresh 10000
1001 ramesh 20000
i want to add a column name is ''doj varchar '' between columns ''ename''
and ''salary''.
i dont want a add last only , i want to add a column only between
''ename'' and ''salary''
give me some example
thanks u sir

推荐答案

您好,


目前,这是不可能的使用单一陈述。你可以在这里投票给这个建议


http://lab.msdn.microsoft.com/produc...b-b56f330a2cfa


在此期间,您可以使用Enterprise Manager或Management Studio来进行此修改(重新创建表并复制数据,

a)非常危险的事情要做生产环境)。请参阅:
http://www.aspfaq.com/ show.asp?id = 2528


Razvan

Hello,

Currently, this is not possible using a single statement. You can vote
for this suggestion here:
http://lab.msdn.microsoft.com/produc...b-b56f330a2cfa

In the meantime, you can use Enterprise Manager or Management Studio to
make this modification (which recreates the table and copies the data,
a pretty dangerous thing to do in a production environment). See:
http://www.aspfaq.com/show.asp?id=2528

Razvan





没有必要以正确的顺序将列放在表中,

因为您可以根据需要通过选择或视图对它们进行排序。

还有一种方法是将列放在中间之间。因为

不需要。如果你真的想这样做(但我建议你不要这么做),你必须用

之间的新栏重新创建表格并复制。从旧表到新表的数据。

HTH,Jens Suessmeyer。


---
http://www.sqlserver2005.de

---

Hi,

there is no need to put the columns in a table in a correct order,
because you can sort them via the select or a view as you want to.
There is further no way to put a column "in between" because there is
no need to. If you really want to do this (but I would suggest you not
to do this) you have to recreate the table with the new column in
between and copy alle the data from the old table to the new table.
HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---


Jens(Je**@sqlserver2005.de)写道:
Jens (Je**@sqlserver2005.de) writes:
没有必要按正确的顺序将列放在表中,


你怎么知道的?如果Surya说他想在表格中添加一个栏目

,可能是因为这是他的要求。


有几个原因为什么要在

列列表中的任何位置添加新列。我们经常在我们的表中添加列(和drop),如果列顺序是历史性的,那么
将是一个完整的混乱。我尝试按逻辑顺序排列

列,这样就可以更容易地阅读数据库

文档,因此使用&b查看数据更容易。 SELECT *",我们从查询分析器查看数据时使用了很多美元。

还有一种方法可以将列放在中间之间。因为没有必要。


废话。这是SQL Server缺少的一个非常好的功能,如果你看到Razvan发布的链接,你发现那个建议

吸引了不少票数。

如果你真的想这样做(但我建议你不要这样做)你必须重新创建表格,并在
和从旧表到新表的数据。
there is no need to put the columns in a table in a correct order,
How do you know that? If Surya says he wants to add a column in a place
in the table, it is probably because that this is his requirement.

There are several reasons why you want to add new column anywhere in the
column list. We frequently add columns (and drop) to our tables, and it
would be a complete mess, if column order was historic. I try arrange
columns in a logical order, so that it''s easier to read the database
documentation, so it''s easier to view data with "SELECT *", which we
use a lot when looking at data from Query Analyzer.
There is further no way to put a column "in between" because there is
no need to.
Crap. This is a very good feature that is missing from SQL Server, and
if you see the link that Razvan posted, you find that that suggestion
has attracted quite a few votes.
If you really want to do this (but I would suggest you not
to do this) you have to recreate the table with the new column in
between and copy alle the data from the old table to the new table.




是的,这就是我们今天所做的。今天的ALTER TABLE基本上是无价值的b $ b;它只能在特殊情况下使用。


这样做时要记住的重要一点是要记住
重新创建索引,触发器和约束。并移动引用

外键。

-

Erland Sommarskog,SQL Server MVP, es **** @ sommarskog.se


SQL Server 2005联机丛书
http://www.microsoft.com/technet/pro ... ads / books.mspx

SQL Server 2000联机丛书
http://www.microsoft.com/sql/prodinf...ons/books.mspx



Yes, that is what we do today. ALTER TABLE as it is today is essentially
worthless; it can be used only exceptionally.

The important thing to keep in mind when doing this is to remember to
recreate indexes, triggers and constraints. And to move referencing
foreign keys.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

这篇关于在表中添加一列指定的位置..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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