如何在Kdb+中设置具有复合主键的外键?

huangapple go评论99阅读模式
英文:

How to set foreign key with compound primary key in Kdb+?

问题

这里是您要翻译的部分:

"有关如何设置外键的文件已足够,但关于如何设置具有复合主键/外键的文件很少。

我运行以下命令,并报告最后2个“length”。如何正确设置它?

t:([eid:1001 1002 1003] name:DentBeeblebroxPrefect; iq:98 42 126) kt: eid`name xkey kt

td2:([] eid:kt$1003 1001 1002 1001 1002 1001; sc:126 36 92 39 98 42) // lenght
td3:([] eid:kt$1003 1001 1002 1001; name:kt$PrefectDentBeeblebroxDent sc:126 36 92 39) // `length"

英文:

It is sufficient documents about how to set foreign key, but few about how to set with compound primary/foreign key.

I run following commands and the last 2 reported `length. How to set it correctly?

t:([eid:1001 1002 1003] name:`Dent`Beeblebrox`Prefect; iq:98 42 126)
kt: `eid`name xkey kt

td2:([] eid:`kt$1003 1001 1002 1001 1002 1001; sc:126 36 92 39 98 42) // `lenght
td3:([] eid:`kt$1003 1001 1002 1001; name:`kt$`Prefect`Dent`Beeblebrox`Dent sc:126 36 92 39) // `length

答案1

得分: 1

Compound keys can be achieved as outlined in:

q)kt:([eid:1001 1002 1003;name:`Dent`Beeblebrox`Prefect] iq:98 42 126)
q)kt
eid  name      | iq
---------------| ---
1001 Dent      | 98
1002 Beeblebrox| 42
1003 Prefect   | 126
q)td:([] eid:1003 1001 1002 1001; name:`Prefect`Dent`Beeblebrox`Dent; sc:126 36 92 39)
q)td
eid  name       sc
-------------------
1003 Prefect    126
1001 Dent       36
1002 Beeblebrox 92
1001 Dent       39
q)update ktfkey:`kt$(eid,'name) from `td // ,' creates (eid;name) pairs
`td
q)td
eid  name       sc  ktfkey
--------------------------
1003 Prefect    126 2
1001 Dent       36  0
1002 Beeblebrox 92  1
1001 Dent       39  0
q)select eid,name,sc,ktfkey.iq from td
eid  name       sc  iq
-----------------------
1003 Prefect    126 126
1001 Dent       36  98
1002 Beeblebrox 92  42
1001 Dent       39  98
英文:

Compount keys can be achieved as outlined in:

q)kt:([eid:1001 1002 1003;name:`Dent`Beeblebrox`Prefect] iq:98 42 126)
q)kt
eid  name      | iq
---------------| ---
1001 Dent      | 98
1002 Beeblebrox| 42
1003 Prefect   | 126
q)td:([] eid:1003 1001 1002 1001; name:`Prefect`Dent`Beeblebrox`Dent; sc:126 36 92 39)
q)td
eid  name       sc
-------------------
1003 Prefect    126
1001 Dent       36
1002 Beeblebrox 92
1001 Dent       39
q)update ktfkey:`kt$(eid,'name) from `td // ,' creates (eid;name) pairs
`td
q)td
eid  name       sc  ktfkey
--------------------------
1003 Prefect    126 2
1001 Dent       36  0
1002 Beeblebrox 92  1
1001 Dent       39  0
q)select eid,name,sc,ktfkey.iq from td
eid  name       sc  iq
-----------------------
1003 Prefect    126 126
1001 Dent       36  98
1002 Beeblebrox 92  42
1001 Dent       39  98

huangapple
  • 本文由 发表于 2023年6月19日 16:50:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定