Solved

copying a record with a timestamp field

Posted on 2013-11-25
4
309 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:ScottPletcher
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now