英文:
How to set foreign key with compound primary key in Kdb+?
问题
这里是您要翻译的部分:
"有关如何设置外键的文件已足够,但关于如何设置具有复合主键/外键的文件很少。
我运行以下命令,并报告最后2个“length”。如何正确设置它?
t:([eid:1001 1002 1003] name:Dent
BeeblebroxPrefect; 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
DentBeeblebrox
Dent 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论