Solved

copying a record with a timestamp field

Posted on 2013-11-25
4
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 35

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

740 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