Procedure to delete and then insert data

Asked

Viewed 464 times

1

Someone could guide me on how to build a database to delete data from a table (already created with SELECT INTO), every day such an hour and then fill it again. Thank you for your attention.

  • 1

    This you will need to do with a JOB, which perform daily calling your proc.

  • First: Delete why and fill in with what? In my opinion is very vague your question.

  • Andre, I’m sorry it wasn’t easy for you to understand my question. The point is, I created a very large query and it takes a while to "run", so I threw her data to a table using SELECT INTO, only every day I need this query to run again in order to check if there has been any change, so I thought to create a precedent to delete the data from this new table and perform an Insert again after the "giant" query runs.

  • Ok, in case, you can create a JOB on SQL Server or by windows task scheduler to run your routine at the given time. Here is an example of simple proc that can give you a light: CREATE PROCEDURE sp_Limpa_Insere AS BEGIN TRUNCATE TABLE test INSERT INTO TEST VALUES('TEST','TEST') END

  • Show André, already served yes as a light, I appreciate the attention.

1 answer

1

Marcilio first any doubt that has post his example to be able to analyze.

Come on

You can do it this way

You can create a simple time table with # or global with #

Regardless of what you put in your select you will do this way

Drop Table #Select_muito_grande
"Inserir as informações do seu select"
Into #Select_muito_grande
FROM "o restante das informações da sua consulta

NOTE: don’t forget to use WITH (NOLOCK) to optimize the process.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.