如何使用sql server 2005查询将数据一个表复制到另一个表?

时间:2011-10-11 13:28:19

标签: sql-server-2005

我想将数据一个表复制到另一个表

my table out put like this


EnrollNo     CheckIn    CheckOut      DiffTime
92            NULL        NULL        NULL
3032        09:40:00    18:31:00    08:51:00
4011        18:30:00    18:38:00    00:08:00
4019        18:32:00    18:32:00    00:00:00
438         10:00:00    18:32:00    08:32:00

2 个答案:

答案 0 :(得分:6)

插入现有表格

INSERT INTO Destination
            (EnrollNo,
             CheckIn,
             CheckOut,
             DiffTime)
SELECT EnrollNo,
       CheckIn,
       CheckOut,
       DiffTime
FROM   Source  

或者创建一个新表

SELECT EnrollNo,
       CheckIn,
       CheckOut,
       DiffTime
INTO NewTable
FROM   Source  

答案 1 :(得分:1)

非常感谢你。这两个选项都有效。 将表newtable创建为select * from source;

Step1:从FT_customer中选择*; TC_CNO TC_NAMETC_ADDRESS TC_STATE TC_ZIP TC_PHONE TC_REMARKS


 1 TRUE WHEEL   55O HUSK    ER 58702 555-4545   NONE
 2 BIKE SPEC    CPT SHRIV   EL 45678 555-1234   NONE
 3 LE SHOPPE    POMETOWN    KS 54678 555-1234   NONE
 4 AAA BIKE     10 OLDTOWN  NE 56784 555-1234   NONE
 5 JACKS BIKE   24 EGLIN    FL 34567 555-2314   NONE

步骤2:从ft_customer创建表a as select *; 从a;

中选择*

TC_CNO TC_NAMETC_ADDRESS TC_STATE TC_ZIP TC_PHONE TC_REMARKS


 1 TRUE WHEEL   55O HUSK    ER 58702 555-4545   NONE
 2 BIKE SPEC    CPT SHRIV   EL 45678 555-1234   NONE
 3 LE SHOPPE    POMETOWN    KS 54678 555-1234   NONE
 4 AAA BIKE     10 OLDTOWN  NE 56784 555-1234   NONE
 5 JACKS BIKE   24 EGLIN    FL 34567 555-2314   NONE

普里亚

abcpune.com