如何将记录从具有不同结构的一个表复制到另一个表 [英] how to copy records from one table to another with diffrent structure

查看:110
本文介绍了如何将记录从具有不同结构的一个表复制到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii

我有两个表emp(3列)和empwithcontact(4列).我想将所有记录从emp复制到empwithcontact,并在最后一列中默认插入"0000".我已经尝试过...但是发生了错误(语法错误,接近0000)...

hii

i have two tables emp( 3 colums) and empwithcontact (4 columns). i want to copy all records from emp to empwithcontact and in the last column i want to insert "0000" by default. i''ve tried this... but error occoured (incorrect syntax near 0000)...

 INSERT INTO [onlineexam].[dbo].[empwithcontact]
           ([id]
           ,[name]
           ,[address]

SELECT  [id]
       ,[name]
       ,[address]
FROM [onlineexam].[dbo].[emp] ,'0000' 

推荐答案

INSERT INTO [onlineexam].[dbo].[empwithcontact]
([id]
,[名称]
,[地址],[4thcolumnname]

SELECT [id]
,[名称]
,[地址],''0000''
FROM [onlineexam].[dbo].[emp]
INSERT INTO [onlineexam].[dbo].[empwithcontact]
([id]
,[name]
,[address],[4thcolumnname]

SELECT [id]
,[name]
,[address],''0000''
FROM [onlineexam].[dbo].[emp]


尝试一下.
Try this.
INSERT INTO [onlineexam].[dbo].[empwithcontact]
           ([id]
           ,[name]
           ,[address],
           ,[4th_column_name])
 
SELECT  [id]
       ,[name]
       ,[address]
       ,'0000'
FROM [onlineexam].[dbo].[emp] 


这篇关于如何将记录从具有不同结构的一个表复制到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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