使用一组常量插入的 SQL 查询
似乎应该对此进行查询,但我不知道该怎么做。
我有一个包含复合主键的表,其中包含我想要填充数据的两个字段,
我可以从一个表进行插入以填充一半的键,但我想用以下内容填充另一半一组常量 (0, 3, 5, 6, 9) 等...
所以最终结果看起来像这样
+--------------+
|AwesomeTable |
+--------------+
| Id1 | Id2 |
| 1 | 0 |
| 1 | 3 |
| 1 | 5 |
| 1 | 6 |
| 1 | 9 |
| 2 | 0 |
| 2 | 3 |
| ... | ... |
+--------------+
我已经得到了 insert into Awesometable (id1, id2) select id1, [这里需要一些东西]来自表1 [这里需要其他东西]
It seems like there should be a query for this, but I can't think of how to do it.
I've got a table with a composite primary key consisting of two fields I'd like to populate with data,
I can do an insert into from one table to fill up half the keys, but I want to fill up the other half with a set of constants (0, 3, 5, 6, 9) etc...
so the end result would look like this
+--------------+
|AwesomeTable |
+--------------+
| Id1 | Id2 |
| 1 | 0 |
| 1 | 3 |
| 1 | 5 |
| 1 | 6 |
| 1 | 9 |
| 2 | 0 |
| 2 | 3 |
| ... | ... |
+--------------+
I've got as far as insert into awesometable (id1, id2) select id1, [need something here] from table1 [need something else here]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,你没有。一张表只能有一个主键。您可能指的是复合主键。
我相信你想要这个:
,或者在 Oracle 中:
No, you don't. A table can only have one primary key. You probably mean a composite primary key.
I believe you want this:
, or in
Oracle
:如果我理解正确的话,也许你可以使用这样的东西:
If I understand correctly, maybe you can use something like this: