MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050

后端 未结 9 1501
温柔的废话
温柔的废话 2021-02-01 00:16

Using the command:

CREATE TABLE IF NOT EXISTS `test`.`t1` (
    `col` VARCHAR(16) NOT NULL
) ENGINE=MEMORY;

Running this twice in the MySQL Que

9条回答
  •  醉话见心
    2021-02-01 00:47

    Well there are lot of answeres already provided and lot are making sense too.

    Some mentioned it is just warning and some giving a temp way to disable warnings. All that will work but add risk when number of transactions in your DB is high.

    I came across similar situation today and here is the query I came up with...

    declare
    begin
      execute immediate '
        create table "TBL" ("ID" number not null)';
      exception when others then
        if SQLCODE = -955 then null; else raise; end if;
    end;
    /
    

    This is simple, if exception come while running query it will be suppressed. and you can use same for SQL or Oracle.

提交回复
热议问题