![]() ![]() The problem here is that you won’t be able to drop the table if it’s referenced in other tables. Please notice here that the keys were not backed up and therefore if you’ll need to recreate the original customer table from the customer_backup table, you’ll need to do one of the following (this is not only SQL best practice but required to keep the referential integrity):Ĭompletely delete the customer table (using the command DROP TABLE customer ), and re-create it from the customer_backup table (the same way we’ve created backup). If you need a simple way to back up a table, except options on the GUI (which are specific to different tools), you have a very simple SQL command at your disposal. ![]() And second – in case something went wrong, you can easily revert everything. ![]() First, you’ll be able to compare old and new data and draw a conclusion if everything went as planned. Maybe the most important SQL Best Practice – Create BackupsĬreating a backup is not only SQL best practice but also a good habit, and, in my opinion, you should backup table(s) (even the whole database) when you’re performing a large number of data changes. We’ll create table backup and update a few rows in this table. Still, we’ll focus only on one table and that is the customer table. We’ll use the same data model we’re using in this series. We’re not talking about regular/expected changes, but rather about manual changes which will be required from time to time. Today, we’ll talk about SQL best practices when performing deletes and updates. Deleting and updating data is very common, but if performed without taking care, which could lead to inconsistent data or data loss. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |