﻿<?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?)  » Import SQL DB - PK comes over as Unique constraint</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 08:51:09 GMT</lastBuildDate><ttl>20</ttl><item><title>Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10617.aspx</link><description>I imported a VFP database to DDT, made the necessary corrections and created a SQL database.&lt;/P&gt;&lt;P&gt;All went well.&amp;nbsp; Then realized I didn't want clustered UID pks. Made the change in DDT but DDT could not uncluster the indexes ( error said they had to be dropped and recreated and DDT didn't seem to want to do that ) &lt;/P&gt;&lt;P&gt;Okay, so I used T-SQL to drop all constraints, keys etc on all the tables in the sql dbc.&amp;nbsp; Then I recreated all the pks as non-clustered.&lt;/P&gt;&lt;P&gt;Now I wanted to reimport into DDT.&amp;nbsp; Decided to do it into a different project.&amp;nbsp; i think that is where it started to go wrong.&amp;nbsp; All the structure came over and the indexes came over but they are just unique constraints - not primary keys and will not accept a default value of NEWID()&lt;/P&gt;&lt;P&gt;They show up as primary in the field list&lt;/P&gt;&lt;P&gt;but the index&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/f8a7a7ee-578b-4edd-9e44-e963.jpg"&gt;&lt;/P&gt;&lt;P&gt;If I try to add NEWID() as a default value I get&lt;/P&gt;&lt;P&gt;DataLayerSavingException&lt;BR&gt;&amp;nbsp; The INSERT statement conflicted with the FOREIGN KEY constraint "fk_indexes_indexfields". The conflict occurred in database "StrataFrame", table "dbo.DBEIndexes", column 'idx_pk'.&lt;BR&gt;The statement has been terminated.&lt;BR&gt;SqlException&lt;BR&gt;&amp;nbsp; The INSERT statement conflicted with the FOREIGN KEY constraint "fk_indexes_indexfields". The conflict occurred in database "StrataFrame", table "dbo.DBEIndexes", column 'idx_pk'.&lt;BR&gt;The statement has been terminated.&lt;/P&gt;&lt;P&gt;I haven't had this problem with my other databases&lt;/P&gt;&lt;P&gt;I tried completely deleting all the DDT projects connected with this database and then importing to a new project in DDT but get the same result.&lt;/P&gt;&lt;P&gt;To test this :&lt;/P&gt;&lt;P&gt;I created a new database called Testit.&amp;nbsp; One table Names ( ckey UID, cname char(10) )&lt;/P&gt;&lt;P&gt;Created PK on ckey&lt;/P&gt;&lt;P&gt;Imported into a new DDT project and got the same result.&amp;nbsp; pk_ckey is Unique Constraint, not PK&lt;/P&gt;&lt;P&gt;Am I doing something wrong or is this a bug?&amp;nbsp; Don't think I had this problem in 1.6</description><pubDate>Mon, 06 Aug 2007 14:41:47 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10734.aspx</link><description>Thanks!&lt;/P&gt;&lt;P&gt;FWIW here is a little more on this to throw in the notes :&lt;/P&gt;&lt;P&gt;After importing tables with UID pks and having them show up in the index node in DDT as a unique constraint but not a pk ( though the pk in the field list is still correctly identifiied ) I did as you suggested - deleted the index in the index node, opened the table in DDT and saved it.&amp;nbsp; The PK then showed correctly on the node ( you asked about this earlier in this thread )&lt;/P&gt;&lt;P&gt;I manually corrected all the tables in the DDT this way, dropped the database in SQL Server and deployed from DDT.&lt;/P&gt;&lt;P&gt;All seems well except there is a constraint that would not be there if this had been created in SQL.&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/a681d367-6662-45ac-9e67-972c.jpg"&gt;&amp;nbsp;&amp;nbsp; &lt;IMG src="http://forum.strataframe.net/Uploads/Images/21b58e07-c4d0-4975-8cca-0734.jpg"&gt;&lt;/P&gt;&lt;P&gt;I have no idea if this is ever going to make a difference on the sql end and if this is just an anomaly created by dropping the constraint from the index node in DDT and having the Pk automatically replace it.&amp;nbsp; But it is a little disturbing that there is nothing in DDT ( or at least I don't see it ) &amp;nbsp;to indicate this constraint is still going to be deployed after being deleted.&amp;nbsp; ( I realize a pk is itself a constraint, but the DF_agent_ckey seems gratuitous and I don't know if it may get me in trouble in some other way so I am just going to write a script in sql to drop all the dk_ constraints )&amp;nbsp; Just wanted you to know that deleting it in the DDT node doesn't seem to keep it from being deployed.&lt;/P&gt;&lt;P&gt;I'm attaching the package just so you can see what is under the hood.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Realize you have other stuff on your plate and I can work around this for now but&lt;/P&gt;&lt;P&gt;How would I roll back to DDT 1.6 for now as I don't think the importing from SQL table problem exists there?&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;&lt;P&gt;Charles</description><pubDate>Mon, 06 Aug 2007 14:41:47 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10729.aspx</link><description>Charles,&lt;/P&gt;&lt;P&gt;I have not reproduced this one issue just yet.&amp;nbsp; I beleive you, I just have not got it in a reproducable format yet since I need to go manually create a SQL table first....I always use the DDT :).&amp;nbsp; So it is on my list of things to reproduce before the next release, but I just&amp;nbsp;have not had the chance to reproduce this yet.</description><pubDate>Mon, 06 Aug 2007 10:37:07 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10727.aspx</link><description>Have you had any luck reproducing this?&amp;nbsp; &lt;/P&gt;&lt;P&gt;UID pks are definitely not importing correctly from SQL 2005 databases into DDT</description><pubDate>Mon, 06 Aug 2007 09:29:01 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10681.aspx</link><description>Charles, &lt;/P&gt;&lt;P&gt;Thanks for all of your kind words.&amp;nbsp; We will look into this.&amp;nbsp; Thanks for the info.</description><pubDate>Thu, 02 Aug 2007 09:41:56 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10661.aspx</link><description>This seems to be a UID issue.&amp;nbsp; &lt;/P&gt;&lt;P&gt;If I create a table with an integer identity primary key it imports as expected.&amp;nbsp; Create exactly the same thing with a UID as pk and the key become a unique constraint instead of a pk&lt;/P&gt;&lt;P&gt;I'm pretty sure this is a bug .:)</description><pubDate>Wed, 01 Aug 2007 11:10:00 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10650.aspx</link><description>In the DDT project for the sample I outlined above if I delete the Index under the index node the ckey field remains checked as primary but on save a true pk index is in the node as it should be and all is well.&lt;P&gt;I think that in 1.6 - my first exposure to DDT when I was testing everything - importing the test database I outlined above would have created a pk index without problems.&amp;nbsp; &lt;/P&gt;&lt;P&gt;I'll be curious to know if anyone who still has 1.6 can confirm that or what results you get in running the test against 1.61&lt;/P&gt;&lt;P&gt;( understand - these nit pickings are small ones - the DDT is one of the most incredible tools i've experienced in 25 years of playing with databases.&amp;nbsp; I'm currently talking it up in the VFP community as a must-have even if you aren't doing .NET. :) )&lt;/P&gt;&lt;P&gt;TIA</description><pubDate>Tue, 31 Jul 2007 14:16:08 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10645.aspx</link><description>I will try to set this up and test it later.&amp;nbsp; One question though, if you manually delete the index then modify the structures for the table then click Save, it should re-create the index for you.&amp;nbsp; Does the index get created properly after the save?</description><pubDate>Tue, 31 Jul 2007 10:49:28 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10637.aspx</link><description>I think I just complicated the problem with the way I asked the question :)&lt;P&gt;The problem is not going from DDT to deployment, but in importing an existing SQL DB&lt;/P&gt;&lt;P&gt;Please try this : Create SQL database Testit.&amp;nbsp; Create 1 table Names ( ckey UID, cname CHAR(10))&lt;/P&gt;&lt;P&gt;Put PK on ckey ( seems to not matter if clustered or non-clustered )&lt;/P&gt;&lt;P&gt;do this directly in SQL Server, not through DDT&lt;/P&gt;&lt;P&gt;Now create a new project in DDT and import Testit.&amp;nbsp; Look at index node and notice it is a Unique Constraint.&amp;nbsp; Try to put a NEWID() default value on ckey&lt;/P&gt;&lt;P&gt;What results do you get?</description><pubDate>Mon, 30 Jul 2007 10:26:57 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Import SQL DB - PK comes over as Unique constraint</title><link>http://forum.strataframe.net/FindPost10630.aspx</link><description>I may have missed something, but I am not having a problem.&amp;nbsp; I checked the Primary Key option on the ckey field and it created the index for me.&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/6fad31bc-4af6-49e7-959e-21f4.png"&gt;&lt;/P&gt;&lt;P&gt;If you then look at the index, it has created the clustered index properly.&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/dfcbc74d-209a-4c97-ab65-153c.png"&gt;&lt;/P&gt;&lt;P&gt;Please let me know if I am not understanding your problem.&amp;nbsp; Thanks. :)</description><pubDate>Mon, 30 Jul 2007 09:19:16 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>