Setting a Foreign Key on a filled table?

Content-Disposition: inline Hello,

I have the following:
q) S1:([SC_ID:()]SC_NAME:())
q) I1:([IN_ID:()]IN_NAME:() ;IN_SC_ID:())
q)meta I1

c       t f a
IN_ID   s
IN_NAME C
IN_SC_ID s
q)meta S1
c      t f a
------- -----
SC_ID  s
SC_NAME C

I now want to set the IN_SC_ID of I1 as a foreign key: S1’s primary key SC_ID.

Typical definition for an empty table could have been
q) I1:([IN_ID:()]IN_NAME:() ;IN_SC_ID:`S1$())

Is it possible to set the foreign key _after_ I1 & S1 have been filled? Or should it be part of the schema definition?

(Assuming that the values are available and there are no errors in the data)

Regards,
Yuva

A foreign key is just a definition of a tie from a column in one tableand its possible usage as a the key into another table (whether simpleor compound). So yes you can apply it after the table has been createdif you like by a simple cast.An example with a tables q and t (note the f setting of q after thecast):q)t:([sym:10#abc] val:til 10)q)meta tc | t f a---| -----sym| sval| iq)q:([] sym:10#abc; val:til 10)q)meta qc | t f a—| -----sym| sval| iq)q[sym]: t$q[sym]q)meta qc | t f a---| -----sym| s tval| iOn 5 Dec, 00:56, "Yuvaraj Athur Raghuvir" <yuvaraj....>wrote:&gt; Hello,&gt;&gt; I have the following:&gt; q) S1:([SC_ID:()]SC_NAME:())&gt; q) I1:([IN_ID:()]IN_NAME:() ;IN_SC_ID:())&gt; q)meta I1&gt; c ? ? ? | t f a&gt; --------| -----&gt; IN_ID ? | s&gt; IN_NAME | C&gt; IN_SC_ID| s&gt; q)meta S1&gt; c ? ? ?| t f a&gt; -------| -----&gt; SC_ID ?| s&gt; SC_NAME| C&gt;&gt; I now want to set the IN_SC_ID of I1 as a foreign key: S1's primary key&gt; SC_ID.&gt;&gt; Typical definition for an empty table could have been&gt; q) I1:([IN_ID:()]IN_NAME:() ;IN_SC_ID:S1$())>> Is it possible to set the foreign key after I1 & S1 have been filled? Or> should it be part of the schema definition?>> (Assuming that the values are available and there are no errors in the data)>> Regards,> Yuva</yuvaraj…>