Very simply:
If I create a table in a database, will it delete or overwrite another table of the same name?
I have a script in a game that needs a table of information. Can I simply run this every time the script starts?:
CREATE TABLE player_data ( UniqueID string, Money int )
So that when someone else runs the script on their game, the table will be created, but if they run it again, it wont be overwritten?
It depends on which database engine you are using. In MySQL there's CREATE TABLE IF NOT EXISTS
to make it will only try to create the table if it does not already exist.
So your statement would look like CREATE TABLE IF NOT EXISTS player_data ( UniqueID string, Money int )
. If there was no table named player_data then a new table would be created. However if there was already a table named player_data then no modifications would occur to the database.
There are usually alternatives for most popular Database Engines to do something similar.
but if they run it again, it wont be overwritten?
No. In general you have to DROP the table first before CREATE succeeds.
There are lots of exceptions to this when it comes to actual implementations, such as if the table is temporary or permanent, access rights where multiple users can have the same table name as long as they all use different user names. Look in your particular server version for such exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With