问题
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 aDEFAULT
into thetimestamp
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