Solved

copying a record with a timestamp field

Posted on 2013-11-25
4
319 Views
Last Modified: 2013-12-11
I wish to insert records from one table into another in the same database.

Both tables have the same structure.

I am using

use mydatabase
insert into Table2
select * from Table1

but I receive the error message "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."

I then tried to use the column list method
USE [mydatabase]
GO

INSERT INTO [dbo].[Table2]
           ([Field1]
           ,[Field2]
           ,[Field3]
           )
     VALUES
           (dbo.Table1.Field1
           ,dbo.Table1.Field2
           ,dbo.Table1.Field3
           )
GO

but this resulted in a list of error messages such as:
"The multi-part identifier "dbo.Table2.Field1" could not be bound."


Can anyone help me update this table?
0
Comment
Question by:Nemetona
4 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39675615
Try
INSERT INTO [dbo].[Table2]
           ([Field1]
           ,[Field2]
           ,[Field3]
           )
SELECT Table1.Field1, Table1.Field2, Table1.Field3
FROM table1


HTH,
Dan
0
 
LVL 5

Expert Comment

by:Lawrence Barnes
ID: 39675620
it also could be that the timestamp column is locked down and the DBA has it defaulting to the current time.

First try this:

Change to:
INSERT INTO [dbo].[Table2]
           ([Field1]
           ,[Field2]
           ,[Field3]
           )
 SELECT Field1, Field2, Field3
FROM dbo.Table1
GO

Otherwise remove the field that has the timestamp and try again.

LVBarnes
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 39675794
INSERT INTO [dbo].[Table2]
           ([Field1]
           ,[Field2]
           ,[Field3]
           )
SELECT
           Field1
           ,Field2
           ,DEFAULT AS Timestamp_Column
FROM dbo.Table1
GO
0
 

Author Closing Comment

by:Nemetona
ID: 39710934
Many thanks, that worked well.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question