1

I have two tables top1 and top2 .First I want to check top1 is empty or not.If top1 is not empty then truncate top2 and insert data from top1. Otherwise dont do any action .

CASE
WHEN top1 is not empty THEN
 Truncate top2
  Insert from Top1

END case
2
  • 4
    SELECT COUNT(*) FROM table_name if this return 0 means your table is empty. Commented May 11, 2016 at 14:31
  • IF EXISTS (SELECT * FROM Table)... Commented May 11, 2016 at 14:55

1 Answer 1

1

Something like the below should do the trick. Provided both of the tables have the same structure....

IF EXISTS(SELECT 1 FROM top1) THEN
  TRUNCATE TABLE Top2;
  INSERT INTO top2 SELECT * FROM top1;
END IF;
Sign up to request clarification or add additional context in comments.

1 Comment

I reallly cannot see what would not work about it. Perhaps you could supply details of the error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.