Solved

copying a record with a timestamp field

Posted on 2013-11-25
4
321 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 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

680 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