Jump to content

Is NOT EXISTS necessary/beneficial


phppup

Recommended Posts

I have discovered that if I try to create a table within a database,  and the table name already exists, the existing table remains intact.

It does not get overwritten or removed. And my code has error messaging to indicate the disparagy.

Likewise, there is built in SQL errors that will be thrown (if made visible).

So, is there any benefit to using:

CREATE TABLE IF NOT EXISTS

as opposed to just CREATE TABLE when writing code??

Edited by phppup
Link to comment
Share on other sites

@requinix

I don't know EXACTLY what you think I should "look carefully" and hope to see.

If it was obvious, i'd have already spotted it, and not have asked the question.

The best I can summize that you're eluding to is that errors occur.

But do those errors affect the end result?

In an instance where I do, in fact, know what tables are in my db, the question is even more appropriate: was NOT EXIST created for only lazy db designers??

Or is there a realistic usage?

Link to comment
Share on other sites

6 hours ago, phppup said:

The best I can summize that you're eluding to is that errors occur.

More or less. Try a regular CREATE TABLE with an existing table name and post the full output of what you get back from the server.

 

6 hours ago, phppup said:

But do those errors affect the end result?

Potentially.

 

6 hours ago, phppup said:

In an instance where I do, in fact, know what tables are in my db, the question is even more appropriate: was NOT EXIST created for only lazy db designers??

I didn't create it so I don't know what the motivation was behind creating it.
I also said that it was my opinion that using IF NOT EXISTS is a symptom of a problem, and though very many people may believe otherwise, opinions are not facts.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.