我有一个这样的 Oracle 数据结构:
俱乐部
Id
Name
一个俱乐部可以拥有多支球队:
团队
Id
Name
ClubId
一个团队可以有很多玩家:
球员
Id
Name
TeamId
我如何插入包含有球员的球队的俱乐部?如果它只是一个有球队的俱乐部,我可以这样做:
Insert all
into Clubs (Id, Name) Values (ClubIdSequence.nextval,'Manchester United')
into Teams (Name, ClubId) Values ('A-Team',ClubIdSequence.currval)
into Teams (Name, ClubId) Values ('B-Team',ClubIdSequence.currval)
Select * from dual
但是我如何插入播放器呢?
这不起作用:
Insert all
into Clubs (Id, Name) Values (ClubIdSequence.nextval,'Manchester United')
into Teams (Id,Name, ClubId) Values (TeamIdSequence.nextval,'A-Team',ClubIdSequence.currval)
into Players (Name,Teamid) Values ('Michael Laudrup',TeamIdSequence.currval
into Teams (Id,Name, ClubId) Values (TeamIdSequence.nextval,'B-Team',ClubIdSequence.currval)
into Players (Name,Teamid) Values ('Brian Laudrup',TeamIdSequence.currval)
Select * from dual
因为
An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level