CodeIgniter Forums
Best way to overwrite certain tables in db - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Best way to overwrite certain tables in db (/showthread.php?tid=71689)



Best way to overwrite certain tables in db - ignitedcms - 09-13-2018

What is the best way to overwrite certain tables in my database?

Should I use migrations?

Or should I do something like this.

#1 Drop the table that needs amending.
#2 Do a mysql insert with new table?

Thank you in advance.


RE: Best way to overwrite certain tables in db - php_rocs - 09-13-2018

@ignitedcms,

I think it depends on the situation. Is there data in them there tables??? If so, are you sure that deleting it is the right path. If you are amending the table you could just do an alter table. I'm always cautious about deleting. I would prefer to backup then delete or if possible rename then recreate.


RE: Best way to overwrite certain tables in db - ignitedcms - 09-13-2018

(09-13-2018, 08:03 AM)php_rocs Wrote: @ignitedcms,

I think it depends on the situation.  Is there data in them there tables???  If so, are you sure that deleting it is the right path.  If you are amending the table you could just do an alter table. I'm always cautious about deleting.  I would prefer to backup then delete or if possible rename then recreate.

Hi thank you for your reply, essentially ONLY one table needs to remain, the rest can be dropped entirely and the new data inserted.


RE: Best way to overwrite certain tables in db - php_rocs - 09-13-2018

@ignitedcms,

Oh, ok. Your just asking a straight database question. I thought is was related to a database with pre-existing data.


RE: Best way to overwrite certain tables in db - InsiteFX - 09-14-2018

This depends on what you need to do.

If you just need to add more fields then use the Alter Table.

If you need to change field names etc; Then you would need to drop the table
and create a new one.


RE: Best way to overwrite certain tables in db - ignitedcms - 09-14-2018

Thank you guys, I think I've got enough ideas to move forward with this.