<?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 Defining a foreign key on a table in PROC SQL that is also the primary key in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-foreign-key-on-a-table-in-PROC-SQL-that-is-also-the/m-p/474182#M121791</link>
    <description>&lt;P&gt;I can't seem to get this to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Neither using just PROC SQL:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table foo (
		id char(10) primary key
	);

	create table bar (
		id char(10) primary key,
		constraint foo_bar_fkey foreign key(id) references foo on delete restrict on update restrict
	);

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or with PROC SQL and PROC DATASETS using the overlapping foreign and primary key section as a guide:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000403555.htm#a002573254" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000403555.htm#a002573254&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table foo (
		id char(10)
	);

	create table bar (
		id char(10)
	);
quit;

proc datasets lib=work;
	modify foo;
		ic create primary key(id);
	modify bar;
		ic create foreign key(id) references foo on delete restrict on update restrict;
	modify bar;
		ic create primary key(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Getting the same error message when trying to create the primary key for bar:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: An index named id with the same definition but different characteristics exists for file WORK.BAR.DATA.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jun 2018 17:35:12 GMT</pubDate>
    <dc:creator>tomcmacdonald</dc:creator>
    <dc:date>2018-06-28T17:35:12Z</dc:date>
    <item>
      <title>Defining a foreign key on a table in PROC SQL that is also the primary key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-foreign-key-on-a-table-in-PROC-SQL-that-is-also-the/m-p/474182#M121791</link>
      <description>&lt;P&gt;I can't seem to get this to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Neither using just PROC SQL:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table foo (
		id char(10) primary key
	);

	create table bar (
		id char(10) primary key,
		constraint foo_bar_fkey foreign key(id) references foo on delete restrict on update restrict
	);

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or with PROC SQL and PROC DATASETS using the overlapping foreign and primary key section as a guide:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000403555.htm#a002573254" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000403555.htm#a002573254&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table foo (
		id char(10)
	);

	create table bar (
		id char(10)
	);
quit;

proc datasets lib=work;
	modify foo;
		ic create primary key(id);
	modify bar;
		ic create foreign key(id) references foo on delete restrict on update restrict;
	modify bar;
		ic create primary key(id);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Getting the same error message when trying to create the primary key for bar:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: An index named id with the same definition but different characteristics exists for file WORK.BAR.DATA.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jun 2018 17:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-foreign-key-on-a-table-in-PROC-SQL-that-is-also-the/m-p/474182#M121791</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2018-06-28T17:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a foreign key on a table in PROC SQL that is also the primary key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Defining-a-foreign-key-on-a-table-in-PROC-SQL-that-is-also-the/m-p/474720#M122006</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142145"&gt;@tomcmacdonald&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;SAS throws this error because you're trying to define ID in table BAR as both a Primary and Foreign key which is not possible.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jul 2018 02:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Defining-a-foreign-key-on-a-table-in-PROC-SQL-that-is-also-the/m-p/474720#M122006</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-07-01T02:11:29Z</dc:date>
    </item>
  </channel>
</rss>

