MySql - Create Table If Not Exists Else Truncate?

前端 未结 6 1675
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 00:23

Here is the updated question:

the current query is doing something like:

$sql1 = \"TRUNCATE TABLE fubar\";
$sql2 = \"CREATE TEMP         


        
6条回答
  •  盖世英雄少女心
    2020-12-31 00:31

    OK then, not bad. To be more specific, the current query is doing something like:

    $sql1 = "TRUNCATE TABLE fubar";
    $sql2 = "CREATE TEMPORARY TABLE IF NOT EXISTS fubar SELECT id, name FROM barfu";
    

    The first time the method containing this is run, it generates an error message on the truncate since the table doesn't exist yet.

    Is my only option to do the "CREATE TABLE", run the "TRUNCATE TABLE", and then fill the table? (3 separate queries)

    PS - thanks for responding so quickly!

提交回复
热议问题