﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Database Deployment Toolkit » Database Deployment Toolkit (How do I?)  » Turning off default PK Clustered index</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Wed, 20 May 2026 06:42:00 GMT</lastBuildDate><ttl>20</ttl><item><title>Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10058.aspx</link><description>I see that my new best friend - the DDT - creates PK indexes as clustered.&lt;br&gt;
&lt;br&gt;
Is there a good way to turn this off, either globally ( in source code ? ) or perhaps there is something I'm missing in the current interface ( writing this before installing 1.61 so if it's there already just point me to it )&lt;br&gt;
&lt;br&gt;
I use a lot of UID PKs in tables I am converting from VFP and my understanding is a clustered index isn't a good idea.&lt;br&gt;
&lt;br&gt;
TIA&lt;br&gt;
&lt;br&gt;
Charles</description><pubDate>Wed, 18 Jul 2007 20:20:55 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10439.aspx</link><description>You guys are terrific.  I'm really glad I asked about this.  Clustered indexes here I come :D</description><pubDate>Wed, 18 Jul 2007 20:20:55 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10329.aspx</link><description>Awesome Ben I&amp;nbsp;knew the property descriptor was there but didn't think to use it! :)&lt;/P&gt;&lt;P&gt;Thanks</description><pubDate>Mon, 16 Jul 2007 18:02:26 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10321.aspx</link><description>Yep, Paul is right... Just override the OnSetDefaultValues() method and set your PK in there by calling whatever method you create to get the sequential guid from the date.&amp;nbsp; &lt;P&gt;[quote]Dim LoPkField As Reflection.PropertyInfo = Me.GetType.GetProperty(Me.PrimaryKeyField)[/quote]&lt;/P&gt;&lt;P&gt;There is a faster way to do that, Paul :)&lt;/P&gt;&lt;P&gt;Imports MicroFour.StrataFrame.Business&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Protected Overrides Sub OnSetDefaultValues()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyBase.OnSetDefaultValues()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Set Value for GUID PK &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Get a reference to the property descriptor (which doesn't use reflection)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim desc As FieldPropertyDescriptor = Me.GetPropertyDescriptor(Me.PrimaryKeyField)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- If the PK is a Guid Generate a Sequential GUID to prevent Index fragmentation&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If desc.PropertyType Is GetType(Guid) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc.SetValue(Me, Common.NewSeqID())&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;End Sub&lt;/P&gt;&lt;P&gt;This way uses the FieldPropertyDescriptors created in the partial class... which are much faster than using reflection ;)&amp;nbsp; Obviously, you're way will work, but the slowness of reflection was the exact reason that we created those descriptors.</description><pubDate>Mon, 16 Jul 2007 16:09:57 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10317.aspx</link><description>Charles,&lt;/P&gt;&lt;P&gt;I am using guids as primekeys as well. I don't think StrataFrame&amp;nbsp;needs to&amp;nbsp;change any source code, you can override the onsetdefaultvalues in&amp;nbsp;your base class Biz object and call out to a function to generate sequential guid based on date.&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;Protected&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Overrides&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; OnSetDefaultValues()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;MyBase&lt;/FONT&gt;&lt;FONT size=2&gt;.OnSetDefaultValues()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'Set Value for GUID PK&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'Get Reference To Primary Key Field Property&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; LoPkField &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Reflection.PropertyInfo = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.GetType.GetProperty(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.PrimaryKeyField)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'If the PK is a Guid Generate a Sequential GUID to prevent Index fragmentation&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; LoPkField.PropertyType &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Is&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;GetType&lt;/FONT&gt;&lt;FONT size=2&gt;(System.Guid) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;LoPkField.SetValue(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;, Common.NewSeqGuid, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Nothing&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Mon, 16 Jul 2007 13:48:22 GMT</pubDate><dc:creator>Paul Chase</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10310.aspx</link><description>Actually, I don't want the server to assign the values.  My goal would be to generate the guid in the new() of the bizobj (is this not the way SF works now?)  Suggestion was to modify whatever algorithm creates the guid now to use a generated sequential guid.  I realize this has to be done without reference to what is currently on the server, so it would probably have to be one of the getdate() methods, but it seems it would add a lot of benefit to using UIDs.  &lt;br&gt;
&lt;br&gt;
I use the newid() as a default on the backend anyway, so that records created outside of SF ( or VFP ) for testing have the UID but my understanding is this isn't going to matter if the new record created by my SF app already has a PK when it hits the server for the insert&lt;br&gt;
&lt;br&gt;
So I guess my question is :  Do I understand correctly that currently when you use a UID PK in a table and generate a new() in a SF BO the guid is created on the front end?  And if so is this code in the source code?&lt;br&gt;
&lt;br&gt;
TIA&lt;br&gt;
&lt;br&gt;
Charles&lt;br&gt;</description><pubDate>Mon, 16 Jul 2007 10:31:28 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10298.aspx</link><description>Yes, using the NewSequentialID() method is awesome, but if you want to use SF with GUIDs and have the server assign the values, you will have to use stored procedures.&amp;nbsp; There is not any way to retrieve the newly assigned value from the DB if you put NewID() or NewSequentialID() in the default values field... it has to be retrieved, stored and then explicitly inserted when you insert the record.&amp;nbsp; So, with SF, that means use sprocs for INSERT and make the PK's parameter an output parameter so it can be retrieved by the DbDataSourceItem and put back into the BO.&amp;nbsp;</description><pubDate>Mon, 16 Jul 2007 08:53:48 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10278.aspx</link><description>I kind of geeked out on this one as GUIDs are such a part of my VFP life.  PKs generated on the backend require a roundtrip to the server before the pk is available for fks in children.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
My understanding is currently when you do a NEW() in a SF bizobj on a UID field the UID is generated client-side.  &lt;br&gt;
&lt;br&gt;
As Ben said, the random nature of UIDs means inserts require a lot of disc thrashing.  But this problem has been solved for years by people using one of many flavors of sequential guids ( just google )  There is even a function on SQL 2005 newsequentialid()&lt;br&gt;
&lt;br&gt;
http://www.sqlmag.com/Article/ArticleID/50164/Dont_Overlook_the_New_SQL_Server_2005_NEWSEQUENTIALID_Function.html&lt;br&gt;
&lt;br&gt;
There are other third party algorithms - written for SQL 2000 before the new function -  that use getdate() as part of the function which I think could be adapted to be used client-side and would therefore be sequential without the round trip.  &lt;br&gt;
&lt;br&gt;
My friend Scott Bellware has posted a really neat solution in his blog&lt;br&gt;
&lt;br&gt;
http://codebetter.com/blogs/scott.bellware/archive/2006/12/27/156671.aspx&lt;br&gt;
&lt;br&gt;
which will probably be the first thing I try. &lt;br&gt;
&lt;br&gt;
Suggest if the MicroFour get a chance they take a look at it and consider implementing something like this in the framework.'&lt;br&gt;
&lt;br&gt;
Now you have best of both worlds (except for the disk space part )  Client side surrogate keys that can be used with clustered indexes ( and replication )&lt;br&gt;
&lt;br&gt;
Thoughts?  :)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description><pubDate>Fri, 13 Jul 2007 12:49:30 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10226.aspx</link><description>The problem with clustered indexes in a GUID field are that the GUIDs are random, so when a new record is inserted, a significant portion of the data on disk has to be moved to insert the records into the middle of the table.&amp;nbsp; However, with integer-based clustered indexes, the integers are normally sequential (like with an IDENTITY spec), so they just get added to the end an no data needs to be moved around.&lt;/P&gt;&lt;P&gt;Now, that being said... clustered indexes are not always bad on GUIDs... it all depends upon the needs of your application.&amp;nbsp; If you need to be able to SELECT records quickly, then use a clustered index... the INSERT speed will suffer, but the SELECT speed will be improved.&amp;nbsp; But, if you insert a bunch of records and don't use them much after that... like in a log file or something, then don't use a clustered index on a GUID field, because you care more about your INSERT speed than your SELECT&amp;nbsp;speed.&lt;/P&gt;&lt;P&gt;Or at least that's what I've always understood from what I've read on clustered indexes :)</description><pubDate>Thu, 12 Jul 2007 09:04:39 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10219.aspx</link><description>Found it, clustered indexes are bad for GUID's, like you said because they take too long to build.&lt;br&gt;
&lt;br&gt;
Learn something every day.</description><pubDate>Wed, 11 Jul 2007 22:34:27 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10218.aspx</link><description>Where did you hear that clustered indexes were bad? and what was the reason if you don't mind?&lt;br&gt;
&lt;br&gt;
The reason I ask is because I just got done creating a SQL mobile app, in SQL Mobile you can only have a single clustered index per table and I found that the access times for clustered versus non-clustered were about 20x faster (in my environment).&lt;br&gt;
&lt;br&gt;
Just curious, because I actually ended up splitting my data into more table than I normally would to be able to have more clustered indexes.</description><pubDate>Wed, 11 Jul 2007 20:54:55 GMT</pubDate><dc:creator>Keith Chisarik</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10070.aspx</link><description>Yeah...you got it figured out!&amp;nbsp; I am glad that you are enjoying it...we like it pretty good too :D</description><pubDate>Sat, 07 Jul 2007 11:14:04 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Turning off default PK Clustered index</title><link>http://forum.strataframe.net/FindPost10061.aspx</link><description>Of course you guys are way ahead of me.  Don't know if it was there in 1.6 but in 1.61 editing a pk lets you turn the cluster off and a whole lot of other stuff.  &lt;br&gt;
&lt;br&gt;
Probably just missed it before.&lt;br&gt;
&lt;br&gt;
LOVE the DDT !!!!   :D&lt;br&gt;
&lt;br&gt;</description><pubDate>Fri, 06 Jul 2007 21:55:25 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item></channel></rss>