是否有像IF NOT EXISTS这样的命令用于插入值?

时间:2014-06-10 18:22:03

标签: java mysql

CREATE TABLE IF NOT EXISTS Orari (ID int AUTO_INCREMENT PRIMARY KEY,titolo Char(40), sala int ,giorno char(10),Ora char(10));

INSERT INTO Orari VALUES (null,null,1,'lunedi','16:30'),
    (null,null,1,'lunedi','19:30'),
    (null,null,2,'lunedi','16:30'),
    (null,null,2,'lunedi','19:30'),
    (null,null,1,'martedi','16:30'),
    (null,null,1,'martedi','19:30'),
    (null,null,2,'martedi','16:30'),
    (null,null,2,'martedi','19:30'),
    (null,null,1,'mercoledi','16:30'),
    (null,null,1,'mercoledi','19:30'),
    (null,null,2,'mercoledi','16:30'),
    (null,null,2,'mercoledi','19:30'),
    (null,null,1,'giovedi','16:30'),
    (null,null,1,'giovedi','19:30'),
    (null,null,2,'giovedi','16:30'),
    (null,null,2,'giovedi','19:30'),
    (null,null,1,'venerdi','16:30'),
    (null,null,1,'venerdi','19:30'),
    (null,null,2,'venerdi','16:30'),
    (null,null,2,'venerdi','19:30'),
    (null,null,1,'sabato','16:30'),
    (null,null,1,'sabato','19:30'),
    (null,null,2,'sabato','16:30'),
    (null,null,2,'sabato','19:30'),
    (null,null,1,'domenica','16:30'),
    (null,null,1,'domenica','19:30'),
    (null,null,2,'domenica','16:30'),
    (null,null,2,'domenica','19:30');

我想把它放在一个函数中,我每次按下按钮都会调用它。

IF NOT EXISTS适用于第一个查询...如果该表已经存在,则会重新创建它。

但是每次按下按钮时,插入值的第二个查询都会一次又一次地插入。

是否有IF NOT EXISTS这样的命令用于插入值?

1 个答案:

答案 0 :(得分:0)

在where子句

中尝试NOT EXISTSEXISTS