<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Recreating tables with integrity constraints in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428962#M13233</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've checked the name several times. I think it is something else. If someone knows why it could be happening, please share &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, the step by step you've said makes sense and it works with the _all_ option, so thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May15&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2018 23:19:05 GMT</pubDate>
    <dc:creator>May15</dc:creator>
    <dc:date>2018-01-18T23:19:05Z</dc:date>
    <item>
      <title>Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427007#M13153</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm recreating tables through data step code with all attributes, formats, informats and labels and then recreating all the integrity constraints through proc datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if a table has a foreign key that is a primary key in another table or vice-versa, I've got an error/warning saying I can't update/delete because of relational integrity constraints. What should be the step by step of recreating tables when they have these kind of constraints?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, it has been done through the user written code transformation (all user written) in SAS DIS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May15&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 20:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427007#M13153</guid>
      <dc:creator>May15</dc:creator>
      <dc:date>2018-01-11T20:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427071#M13159</link>
      <description>&lt;P&gt;You have to drop the foreign key constraint first, then the primary key constraint and then re-create them - this time with the primary key first e.g.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
	set sashelp.class;
run;

data boys;
	set class(where=(sex="M"));
run;

proc datasets lib=work;
	modify class;
	ic create prim = primary key(name);
	modify boys;
	ic create for = foreign key(name) references class;
quit;


proc datasets lib=work;
	modify boys;
	ic delete for;
	modify class;
	ic delete prim;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 00:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427071#M13159</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2018-01-12T00:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427270#M13163</link>
      <description>&lt;P&gt;Hi ChrisBrooks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried something like&amp;nbsp;that&amp;nbsp;but when I try to delete the foreign key I've got a warning saying the foreign key doesn't exist... It doesn't make sense because when I run the proc contents of that table I actually can see it and also in the metadata of the table...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no idea why it is happening. I've checked the syntax and it is ok. I'm doing this in the user written code of SAS DIS, I don't know if it has any impact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2018 16:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427270#M13163</guid>
      <dc:creator>May15</dc:creator>
      <dc:date>2018-01-12T16:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427319#M13164</link>
      <description>That shouldn’t make any difference - can you post the Proc Datasets code you’re using to delete the foreign key along with the Proc Contents output?</description>
      <pubDate>Fri, 12 Jan 2018 18:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427319#M13164</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2018-01-12T18:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427630#M13177</link>
      <description>&lt;P&gt;I can't specify the real fields but it is like you said:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=myLibrary nolist;
modify mytableB;
ic delete forkeymytableB;
modify mytableA;
ic delete primkeymytableA;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where forkeymytableB has the same name as the primkeymytableA (forkeymytableB refers to primkeymytableA)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is the output running the proc contents of mytableB:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17842i7FC1070BEE91DC89/image-size/large?v=v2&amp;amp;px=999" role="button" title="Output.PNG" alt="Output.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May15&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427630#M13177</guid>
      <dc:creator>May15</dc:creator>
      <dc:date>2018-01-15T10:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427645#M13185</link>
      <description>&lt;P&gt;That's strange because the following works for me as expected&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
	set sashelp.class;
run;

data boys;
	set sashelp.class(where=(sex="M"));
run;

proc datasets lib=work;
	modify class;
	ic create mypkey = primary key (name);
	modify boys;
	ic create myfkey= foreign key (name) references class
		on delete restrict on update restrict;
quit;

proc datasets lib=work;
	modify boys;
	ic delete myfkey;
	modify class;
	ic delete mypkey;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try ic delete _all_ instead of naming the keys&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/427645#M13185</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2018-01-15T10:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428767#M13229</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the ic delete _all_ it actually works. I have no idea why it doesn't when I name the keys.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May15&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 12:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428767#M13229</guid>
      <dc:creator>May15</dc:creator>
      <dc:date>2018-01-18T12:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428959#M13232</link>
      <description>&lt;P&gt;It may be that there's something odd about the constraint name which makes it look other than it is e.g. a numeral 1 instead of a letter l or two letter Vs instead of a W or some unprintable character at the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be interesting to know if the problem persists after the constraints have been re-created but in any can if you're happy the problem is resolved it would be appreciated if you could mark the solution as accepted.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 23:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428959#M13232</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2018-01-18T23:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Recreating tables with integrity constraints</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428962#M13233</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've checked the name several times. I think it is something else. If someone knows why it could be happening, please share &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, the step by step you've said makes sense and it works with the _all_ option, so thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May15&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2018 23:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Recreating-tables-with-integrity-constraints/m-p/428962#M13233</guid>
      <dc:creator>May15</dc:creator>
      <dc:date>2018-01-18T23:19:05Z</dc:date>
    </item>
  </channel>
</rss>

