Home > Database > Mysql Tutorial > 使用IF NOT EXISTS创建数据表

使用IF NOT EXISTS创建数据表

WBOY
Release: 2016-06-07 16:48:00
Original
3103 people have browsed it

如果简单的使用如下sql语句可能会返回失败,失败的原因极有可能是已经存在这张数据表了。

如果简单的使用如下sql语句可能会返回失败,失败的原因极有可能是已经存在这张数据表了。

create table  sales3 ( id NUMERIC,sale_date datetime not null)
PARTITION by range(TO_DAYS(sale_date))
(
  PARTITION sales20140301 values less than(TO_DAYS('2014-03-01')),
  PARTITION sales20140401 values less than(TO_DAYS('2014-04-01'))
)

执行时返回的提示语句如下:

[SQL] create table  sales3 ( id NUMERIC,sale_date datetime not null)
PARTITION by range(TO_DAYS(sale_date))
(
  PARTITION sales20140301 values less than(TO_DAYS('2014-03-01')),
  PARTITION sales20140401 values less than(TO_DAYS('2014-04-01'))
)

[Err] 1050 - Table 'sales3' already exists

而如果使用IF NOT EXISTS创建数据表,即使此表已经存在,也会执行成功:

create table IF NOT EXISTS  sales3 ( id NUMERIC,sale_date datetime not null)
PARTITION by range(TO_DAYS(sale_date))
(
  PARTITION sales20140301 values less than(TO_DAYS('2014-03-01')),
  PARTITION sales20140401 values less than(TO_DAYS('2014-04-01'))
)

返回如下:

[SQL] create table  if not exists sales3 ( id NUMERIC,sale_date datetime not null)
PARTITION by range(TO_DAYS(sale_date))
(
  PARTITION sales20140301 values less than(TO_DAYS('2014-03-01')),
  PARTITION sales20140401 values less than(TO_DAYS('2014-04-01'))
)

受影响的行: 0
时间: 0.003ms

本文永久更新链接地址:

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template