如何仅将列复制到sql Server 2005数据库中的另一个表. [英] How to copy only column to another table in sql server 2005 database.

查看:69
本文介绍了如何仅将列复制到sql Server 2005数据库中的另一个表.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

在SqlServer 2005上工作.数据库中有两个表.

表1是历史记录
表2是UserDetails

我有一个带有历史记录"的表名,在这里我有一个统一的名称"TimeStamp",现在我需要将所有这些数据复制到userDetails表中.

如何仅将特定列复制到sqlserver 2005中的另一个表.帮助我.

在此先感谢.

Hello Friends,

am working on SqlServer 2005. I have two tables in my Database.

Table 1 is history
Table 2 is UserDetails

I have a table name with History, In this i have a coulmn name ''TimeStamp'' Now I need to copy all these data to userDetails table.

How to copy only a particular column to another table in sqlserver 2005.. Help me.

thanks in advance.

推荐答案

这可能对您有帮助
This may help you
Insert into UserDetails(TimeStamp)
select TimeStamp from History


如果要复制所有记录,然后将它们作为新记录插入,则

if you are copying all the record, and inserting them as new then

Insert into UserDetails(TimeStamp)
select TimeStamp from History




但是如果您要从历史记录表中复制并将其插入到现有列中,那么




but if you are copying from history table and inserting them to existing column then

update userDetails set TimeStamp= (select TimeStamp from history where history.userID= UserDetails.UserID)
--modify the condition to your needs,



这不会插入新记录,而只会更新现有记录.



this will not insert records as new, but will only update the existing records.


这篇关于如何仅将列复制到sql Server 2005数据库中的另一个表.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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