<?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 cant figure out basic sas sql delect cascade. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cant-figure-out-basic-sas-sql-delect-cascade/m-p/789540#M252650</link>
    <description>&lt;P&gt;Hows it going?&amp;nbsp; noob sas sql question here . Im trying to learn foreign references and what Im trying to do is establish a primary foreign relationship and then delete from the primary and have it auto delete in the table with an associated foreign key .&amp;nbsp; Say I have stopped selling cars &amp;gt; 30000 because no one is buying them.&amp;nbsp; I want to delete all the cars in my records&amp;nbsp; that match this condition from all linked tables by simply deleting the entries in the table with the primary key.&amp;nbsp; I thought that using DELETE CASCADE would accomplish this but I must be missing sth.&amp;nbsp; It says this is not supported or maybe my syntax is wrong?&amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro make_sql;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table k1 (id num , model char , msrp num ) ;&lt;BR /&gt;insert into k1&lt;BR /&gt;select monotonic()*2 as id , model , msrp from sashelp.cars;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;alter table k1&lt;BR /&gt;add constraint prime primary key(id);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table k2 (id num , model char, inventory num );&lt;BR /&gt;insert into k2&lt;BR /&gt;select monotonic()*2 ,model, invoice&lt;BR /&gt;from sashelp.cars;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;alter table k2&lt;BR /&gt;add constraint foreign2 foreign key(id)&lt;BR /&gt;references k1&lt;BR /&gt;on delete cascade ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend make_sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro del_sql;&lt;BR /&gt;proc sql;&lt;BR /&gt;alter table k2&lt;BR /&gt;drop foreign key foreign2;&lt;/P&gt;&lt;P&gt;drop table k1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;drop table k1;&lt;BR /&gt;quit;&lt;BR /&gt;%mend del_sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%make_sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* condition to remove the primary values&amp;nbsp;&lt;BR /&gt;proc sql;&lt;BR /&gt;delete from k1&lt;BR /&gt;where msrp &amp;gt; 30000&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*K1 deletes the values k2 stays the same? ;&lt;/P&gt;&lt;P&gt;proc contents data=k1 ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc contents data=k2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*********************************************************&lt;/P&gt;&lt;P&gt;Ive also replaced ON DELETE CASCADE with ON UPDATE CASCADE&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&amp;nbsp; used below.&amp;nbsp; its not working either so I must be missing sth very basic. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;update k1&lt;BR /&gt;set id = 0&lt;BR /&gt;where msrp &amp;gt; 30000&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jan 2022 17:09:40 GMT</pubDate>
    <dc:creator>thryce85</dc:creator>
    <dc:date>2022-01-11T17:09:40Z</dc:date>
    <item>
      <title>cant figure out basic sas sql delect cascade.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cant-figure-out-basic-sas-sql-delect-cascade/m-p/789540#M252650</link>
      <description>&lt;P&gt;Hows it going?&amp;nbsp; noob sas sql question here . Im trying to learn foreign references and what Im trying to do is establish a primary foreign relationship and then delete from the primary and have it auto delete in the table with an associated foreign key .&amp;nbsp; Say I have stopped selling cars &amp;gt; 30000 because no one is buying them.&amp;nbsp; I want to delete all the cars in my records&amp;nbsp; that match this condition from all linked tables by simply deleting the entries in the table with the primary key.&amp;nbsp; I thought that using DELETE CASCADE would accomplish this but I must be missing sth.&amp;nbsp; It says this is not supported or maybe my syntax is wrong?&amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro make_sql;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table k1 (id num , model char , msrp num ) ;&lt;BR /&gt;insert into k1&lt;BR /&gt;select monotonic()*2 as id , model , msrp from sashelp.cars;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;alter table k1&lt;BR /&gt;add constraint prime primary key(id);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table k2 (id num , model char, inventory num );&lt;BR /&gt;insert into k2&lt;BR /&gt;select monotonic()*2 ,model, invoice&lt;BR /&gt;from sashelp.cars;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;alter table k2&lt;BR /&gt;add constraint foreign2 foreign key(id)&lt;BR /&gt;references k1&lt;BR /&gt;on delete cascade ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend make_sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro del_sql;&lt;BR /&gt;proc sql;&lt;BR /&gt;alter table k2&lt;BR /&gt;drop foreign key foreign2;&lt;/P&gt;&lt;P&gt;drop table k1;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;drop table k1;&lt;BR /&gt;quit;&lt;BR /&gt;%mend del_sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%make_sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* condition to remove the primary values&amp;nbsp;&lt;BR /&gt;proc sql;&lt;BR /&gt;delete from k1&lt;BR /&gt;where msrp &amp;gt; 30000&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*K1 deletes the values k2 stays the same? ;&lt;/P&gt;&lt;P&gt;proc contents data=k1 ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc contents data=k2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*********************************************************&lt;/P&gt;&lt;P&gt;Ive also replaced ON DELETE CASCADE with ON UPDATE CASCADE&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&amp;nbsp; used below.&amp;nbsp; its not working either so I must be missing sth very basic. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;update k1&lt;BR /&gt;set id = 0&lt;BR /&gt;where msrp &amp;gt; 30000&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 17:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cant-figure-out-basic-sas-sql-delect-cascade/m-p/789540#M252650</guid>
      <dc:creator>thryce85</dc:creator>
      <dc:date>2022-01-11T17:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: cant figure out basic sas sql delect cascade.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cant-figure-out-basic-sas-sql-delect-cascade/m-p/789573#M252666</link>
      <description>&lt;P&gt;Please post your SAS log. It looks like you are using syntax which isn't supported in SAS SQL and the errors in the SAS log should point to these.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure why you are experimenting with table keys and constraints. Please bear in mind that SAS data libraries are not RDBMSs like Oracle or SQL Server. There is no need to define table schemas before populating the tables - just populate the table and the table "schema" will take care of itself.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 19:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cant-figure-out-basic-sas-sql-delect-cascade/m-p/789573#M252666</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-01-11T19:45:02Z</dc:date>
    </item>
  </channel>
</rss>

