Import Data to Existing Table

馋奶兔 提交于 2020-01-05 05:43:05

问题


How to import data to existing table in Database from another Database in sql

I am trying this but not working . It is saying

'Cannot insert an explicit value into a timestamp column.' Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.

Insert Into [test].[dbo].[Sample$Employee]
select * from [Test1].[dbo].[Sample1$Employee]

Thanks


回答1:


INSERT INTO Target_Table(Column1, Column2, Column3)  
SELECT Column1, Column2, Column3  
FROM Source_Database.Source_Table



回答2:


You can try

INSERT INTO <database>.<schema>.<table>
SELECT * FROM <source_database>.<schema>.<source_table>

After your modification, you need specify columns which you want the insert to the new table.

So your query could be

INSERT INTO <database>.<schema>.<table>([Column1], [Column1], [Column1])
SELECT [Column1],[Column2],[Column3] FROM <source_database>.<schema>.source_table>

As I can see from the error message, you need implicitly define a column type.

For example: If your column has type DATE you need use CAST(Column AS DATE) AS [Column_Name].




回答3:


Your table has a column of type timestamp, aka rowversion. A column of this type cannot be written to.

Instead of using *, which includes the column you can't copy, write out the column list and omit the colum of type timestamp.




回答4:


The error message actually gives you the answer you are looking for:

Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column.

EDIT

TIMESTAMP columns cannot be explicitly written to, and you need to exclude this column from your insert statement, or... if you really want the timestamp data moved from the source table, then you will need to change the type of the corresponding field in the destination table.




回答5:


Try this:

Select * into SQLShackDemo.HumanResources.Department 
from AdventureWorks2012.HumanResources.Department 


来源:https://stackoverflow.com/questions/48982675/import-data-to-existing-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!