Schema maintenance scripts
As you are developing a database schema, there may be occasions on which you have to
change your mind about a table or column definition. For example, you may have underestimated
the column size for a primary key field. In that case, you would need to update the table
definition - possibly using an ALTER TABLE
statement. However, if that column is referenced
in a foreign key in another table, you will need to update that column definition as well.
Similarly, if you decide to change the name of a column, you will need to change it wherever
it is referenced. One change may have consequences like this which can cause errors to creep
into your structures.
Rather than making each change individually and directly on the database, keeping a database maintenance script allows you to make changes quickly and easily. A maintenance script is a series of SQL statements in a text file which recreates the database every time it is run. First it removes any existing database objects (see below), and then it goes on to create the required objects and finally to insert the data. Having all of your maintenance statements in a single file means that you can make changes easily by using the standard global search and replace functions of a text editor.
The code below shows a simple example of a schema maintenance script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|