<p>As part of our current database work, we are looking at a dealing with the process of updating databases.</p>

<p>A point which has been brought up recurrently, is that of dealing with system vs. user values; in our project user and system vals are stored together. For example...</p>

<p>We have a list of templates.</p>

<pre><code>1, &lt;system template&gt;

2, &lt;system template&gt;

3, &lt;system template&gt;
</code></pre>

<p>These are mapped in the app to an enum (1, 2, 3)</p>

<p>Then a user comes in and adds...</p>

<pre><code>4, &lt;user template&gt;
</code></pre>

<p>...and...</p>

<pre><code>5, &lt;user template&gt;
</code></pre>

<p>Then.. we issue an upgrade.. and insert as part of our upgrade scripts...</p>

<pre><code>&lt;new id&gt; [6], &lt;new system template&gt;
</code></pre>

<p>THEN!!... we find a bug in the new system template and need to update it... The problem is how? We cannot update record using ID6 (as we may have inserted it as 9, or 999, so we have to identify the record using some other mechanism)</p>

<p>So, we've come to two possible solutions for this.</p>

<h2><strong>In the red corner (speed)....</strong></h2>

<p>We simply start user Ids at 5000 (or some other value) and test data at 10000 (or some other value). This would allow us to make modifications to system values and test them up to the lower limit of the next ID range. </p>

<p>Advantage...Quick and easy to implement, </p>

<p>Disadvantage... could run out of values if we don't choose a big enough range!</p>

<h2><strong>In the blue corner (scalability)...</strong></h2>

<p>We store, system and user data separately, use GUIDs as Ids and merge the two lists using a view.</p>

<p>Advantage...Scalable..No limits w/regard to DB size. </p>

<p>Disadvantage.. More complicated to implement. (many to one updatable views etc.)</p>

<hr>

<p>I plump squarely for the first option, but looking for some ammo to back me up!</p>

<p>Does anyone have any thoughts on these approaches, or even one(s) that we've missed?</p>

[{'answer_id': 9707, 'author': 'John Smithers', 'author_id': 1069, 'author_profile': 'https://Stackoverflow.com/users/1069', 'pm_score': 0, 'selected': False, 'text': "<p>Maybe I didn't get it, but couldn't you use GUIDs as Ids and still have user and system data together? Then you can access the system data by the (non-changable) GUIDs.</p>\n"}, {'answer_id': 9713, 'author': 'Biri', 'author_id': 968, 'author_profile': 'https://Stackoverflow.com/users/968', 'pm_score': 1, 'selected': False, 'text': '<p>I recommend using the second with the modification that you store the system and user values in one table. GUID is quite reliable in this manner.</p>\n\n<p>Another idea: use any text-based ID (not necessary GUID), which you give for the system values and is generated by a random string or a string based on some kind of custom logic for the user values.</p>\n\n<p>Another idea: use the first approach, but extend the table with a flag which shows if a value is system or user. Maybe this is the easiest. Ok, you have to write some kind of mechanism to update the correct system value, but it can be done easily.</p>\n'}, {'answer_id': 9728, 'author': 'Biri', 'author_id': 968, 'author_profile': 'https://Stackoverflow.com/users/968', 'pm_score': 0, 'selected': False, 'text': "<p>I don't think that GUID should make any problem.</p>\n\n<p>If you want to avoid it, then use a flag:</p>\n\n<blockquote>\n  <p>ID int</p>\n  \n  <p>template whatever</p>\n  \n  <p>flag enum/int/bool</p>\n</blockquote>\n\n<p>Flag shows whether the actual value is a system or a user value.</p>\n\n<p>If you would like to update a system value, then ask only for system values ordered by ID, and it will show you actual order of insertion (you should have a bigint or something for ID to make sure that it doesn't get full and it doesn't get the deleted IDs back to work). With this list the x. record is the x. inserted system value.</p>\n"}, {'answer_id': 9731, 'author': 'ninesided', 'author_id': 1030, 'author_profile': 'https://Stackoverflow.com/users/1030', 'pm_score': 1, 'selected': False, 'text': '<p>+1 for Biri\'s text based ID - define a "template_mnemonic" text based column and make it the primary key. This will be a known value when you insert it as you, the developers will have decided on it (or auto-generated it) and you will always be able to reference a template by its mnemonic regardless of how many user specified templates there are. It also allows users to have a meaningful naming convention for their templates.</p>\n'}, {'answer_id': 9857, 'author': 'RobertTheGrey', 'author_id': 1107, 'author_profile': 'https://Stackoverflow.com/users/1107', 'pm_score': 2, 'selected': True, 'text': '<p>I have never had problems (performance or development - TDD &amp; unit testing included) using GUIDs as the ID for my databases, and I\'ve worked on some pretty big ones. Have a look <a href="http://www.sql-server-performance.com/articles/per/guid_performance_p2.aspx" rel="nofollow noreferrer">here</a>, <a href="http://weblogs.asp.net/wwright/archive/2007/11/04/the-gospel-of-the-guid-and-why-it-matters.aspx" rel="nofollow noreferrer">here</a> and <a href="http://weblogs.asp.net/wwright/archive/2007/11/11/gospel-of-the-guid-answers-to-your-burning-questions-comments-and-insults.aspx" rel="nofollow noreferrer">here</a> if you want to find out more about using GUIDs (and the potential GOTCHAS involved) as your primary keys - but I can\'t recommend it highly enough since moving data around safely and DB synchronisation becomes as easy as brushing your teeth in the morning :-)</p>\n\n<p>For your question above, I would either recommend a third column (if possible) that indicates whether or not the template is user or system based, or you can at the very least generate GUIDs for system templates as you insert them and keep a list of those on hand, so that if you need to update the template, you can just target that same GUID in your DEV, UAT and /or PRODUCTION databases without fear of overwriting other templates. The third column would come in handy though for selecting all system or user templates at will, without the need to seperate them into two tables (this is overkill IMHO).</p>\n\n<p>I hope that helps,</p>\n\n<p>Rob G</p>\n'}, {'answer_id': 14660, 'author': 'David Hayes', 'author_id': 1769, 'author_profile': 'https://Stackoverflow.com/users/1769', 'pm_score': 0, 'selected': False, 'text': "<p>I think there is a better third solution. \nIt strikes me that you're storing two different things in the same table and that you might be better off creating 2 separate tables one for user templates and one for system templates. You might then be able to create a view over the two tables to make them appear as a single object to your application. \nObviously I don't have full knowledge of your application and this may be impossible for you for any number of reasons but I think it's a neater solution than GUIDs and way safer than ranges of IDs (seriously don't do ID ranges it'll bite you one day)</p>\n"}]
['https://Stackoverflow.com/questions/9702', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1193/']