请教数据库专家个初级问题,这个用t-sql怎么写?

if I create a table as below:

CREATE TABLE table1(
column1 varchar(50),
column2 varchar(50),
column3 varchar(50),
column4 varchar(50));

what is the code for adding the column named “columnX” after column2 to the table shown above?


ALTER TABLE table1 ADD columnX varchar(50)
可以add a new column,但怎么加到指定位置呢(after column2)?

所有跟帖: 

美国老土,it's a piece of cake for you, thanks! -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/27/2009 postreply 10:45:17

no can't do, have to drop and recreate -forweb- 给 forweb 发送悄悄话 (0 bytes) () 04/27/2009 postreply 10:52:41

Thanks. This is just what I thought. but -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (75 bytes) () 04/27/2009 postreply 10:59:59

Select * into table2 from table1 -oops_yz- 给 oops_yz 发送悄悄话 (58 bytes) () 04/27/2009 postreply 11:06:17

好! 谢谢:)。就是想确定一下:没有办法可以直接一步到位? -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/27/2009 postreply 11:10:41

wow!!! -HappyNow?!- 给 HappyNow?! 发送悄悄话 HappyNow?! 的博客首页 (970 bytes) () 04/27/2009 postreply 11:35:05

wow!!! fancy to see you again, HappyNow?!! . how r u doing, bud -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (67 bytes) () 04/27/2009 postreply 11:49:01

In MySQL, you can easily do it. -竹杉林- 给 竹杉林 发送悄悄话 竹杉林 的博客首页 (64 bytes) () 04/27/2009 postreply 12:28:25

oh, I love it. But t-sql doesn't support the key "after" ..:) -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/27/2009 postreply 12:38:32

then I don't know. -竹杉林- 给 竹杉林 发送悄悄话 竹杉林 的博客首页 (0 bytes) () 04/27/2009 postreply 12:51:33

Don't you hint t-sql supports the key "before"? haha. -竹杉林- 给 竹杉林 发送悄悄话 竹杉林 的博客首页 (0 bytes) () 04/27/2009 postreply 12:52:42

为什么要非要插入到这个位置呢? -小丹尼- 给 小丹尼 发送悄悄话 (108 bytes) () 04/27/2009 postreply 13:25:20

agreed; but "look/feel" good to the designer -:))) -HappyNow?!- 给 HappyNow?! 发送悄悄话 HappyNow?! 的博客首页 (0 bytes) () 04/27/2009 postreply 13:30:59

我觉得这没有必要,本来数据和表现就应该分开 -小丹尼- 给 小丹尼 发送悄悄话 (77 bytes) () 04/27/2009 postreply 13:34:27

when you use "select * from", -竹杉林- 给 竹杉林 发送悄悄话 竹杉林 的博客首页 (28 bytes) () 04/27/2009 postreply 13:32:45

个人以为,select *不是一个好的SQL习惯 -小丹尼- 给 小丹尼 发送悄悄话 (32 bytes) () 04/27/2009 postreply 13:43:23

有道理。谢谢。在学这个,是书上的一道题目:) -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/27/2009 postreply 13:54:57

帮你查了一下 -安心草- 给 安心草 发送悄悄话 安心草 的博客首页 (110 bytes) () 04/27/2009 postreply 14:06:30

xiexiexiexie, my smarty:) -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/27/2009 postreply 14:15:12

In SQL management studio -ExpectingMM- 给 ExpectingMM 发送悄悄话 (159 bytes) () 04/27/2009 postreply 18:40:41

Thanks, ExpectingMM. very busy? -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/27/2009 postreply 20:25:56

agree,基本上schama的改变不太用t-sql来做 -撅着挺好- 给 撅着挺好 发送悄悄话 (89 bytes) () 04/28/2009 postreply 04:43:48

:) thanks. -戏雨飞鹰- 给 戏雨飞鹰 发送悄悄话 戏雨飞鹰 的博客首页 (0 bytes) () 04/28/2009 postreply 14:00:05

请您先登陆,再发跟帖!