首页 > 解决方案 > 如何在 MySQL 数据库上使用“如果不存在”

问题描述

如何if not exists在 MySQL 数据库中使用。

create schema if not exists appkasir;

use appkasir;

create table if not exists admin (
    id int(11) not null auto_increment,
    nama varchar(20) not null,
    no_telp varchar(20) null,
    alamat varchar(50) null,
    email varchar(50) null,
    primary key (id)
);

标签: phpmysqlsqlxamppexists

解决方案


你没有给出任何错误信息。我认为这不是主键的错误,if exists但可能是主键的错误。

查看MySQL 参考资料

尝试:

create schema if not exists appkasir;

use appkasir;

create table if not exists admin (
    id int(11) not null auto_increment primary key,
    nama varchar(20) not null,
    no_telp varchar(20) null,
    alamat varchar(50) null,
    email varchar(50) null
);

推荐阅读