Use if not exists to create a data table

Source: Internet
Author: User

If you simply use the following SQL statement, failure may be returned. The cause of failure is that the data table already exists.

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

The prompt statement returned during execution is as follows:

[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 ('2017-03-01 ')),
PARTITION sales20140401 values less than (TO_DAYS ('2017-04-01 '))
)

[Err] 1050-Table 'sales3' already exists

IF you use if not exists to create a data table, the operation is successful even IF the table already 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 ('2017-03-01 ')),
PARTITION sales20140401 values less than (TO_DAYS ('2017-04-01 '))
)

The returned result is as follows:

[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 ('2017-03-01 ')),
PARTITION sales20140401 values less than (TO_DAYS ('2017-04-01 '))
)

Affected rows: 0
Date: 0.003 ms

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.