phppup Posted November 19, 2020 Share Posted November 19, 2020 (edited) 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 November 19, 2020 by phppup Quote Link to comment Share on other sites More sharing options...
requinix Posted November 19, 2020 Share Posted November 19, 2020 Exactly what happens when you try a regular CREATE TABLE? Look carefully. And opinion: if you need IF NOT EXISTS then that means you don't know what is happening to your database. You should always know whether the table exists or not. Quote Link to comment Share on other sites More sharing options...
phppup Posted November 24, 2020 Author Share Posted November 24, 2020 @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? Quote Link to comment Share on other sites More sharing options...
requinix Posted November 24, 2020 Share Posted November 24, 2020 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.