Hello
I am new to this forum.

I am using MS SQL 2005 Express

I have a database GK.dbo (the original databese) and I have created a database GK_2009.dbo (it is created from the original database, so it has the same structure)
I want to create a script that would copy a table from GK database to GK_2009 database and after the copying is finished and verified, the data from the table in the GK database, must be deleted (only data, and not the table). I need it for the scheduled data copying, and I will use Windows Scheduled task. is it possible to do it? how can I do it?

regards,
vedro

SELECT * INTO DESTTABLE FROM Prevdb.dbo.Currenttable;
DLETE FROM Prevdb.dbo.Currenttable

Hello

I am known with those commands.
How would a script look, that could perform this action in scheduled task?

regards,
vedro

Hello

I have managed to write a working script:

It is a Stored Procedure script. If anyone else will need something alike:

CREATE PROCEDURE usp_BackupTableAlarmi
AS
SET XACT_ABORT ON
BEGIN TRANSACTION 
BEGIN TRY
SELECT * INTO GK_2009.dbo.Alarmi FROM GK.dbo.Alarmi
TRUNCATE table Alarmi
COMMIT TRANSACTION;
END TRY 
BEGIN CATCH 
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT ERROR_MESSAGE(); 
END CATCH;

Regards,
vedro

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.