gpt4 book ai didi

mysql - 关于sql插入日期

转载 作者:行者123 更新时间:2023-11-29 11:36:51 24 4
gpt4 key购买 nike

这是我的 table

Create table artist_song (
Artist_id int not null,
Song_id int not null,
Artist_song_type varchar(255) not null,
Artist_song_order int not null,
Constraint artist_song_pk primary key (artist_id, song_id),
Constraint artist_song_fk1 foreign key(artist_id) references artist(artist_id),
Constraint artist_song_fk2 foreign key(song_id) references song(song_id)
);

我想插入日期

INSERT INTO artist_song (artist_id, song_id, artist_song_type, artist_song_order) VALUES (2,13,'music',1);

但它说的是

14:19:27    INSERT INTO artist_song (artist_id, song_id, artist_song_type, artist_song_order) VALUES (2,13,'music',1)   Error Code: 1062. 
Duplicate entry '2-13' for key 'PRIMARY' 0.000 sec

我应该做什么?我需要更改 Artist_id 吗?

最佳答案

所以这里创建了复合键,或者复合主键,是指使用多个列来指定表的主键的情况。

看来您的数据库表中已经存在一条包含“2-13”条目的记录。请检查您的表。

因此,在您的表中必须有值为 2 的“artist_id”和值为 13 的“song_id”。

因此,每当您定义主键时,它在整个列中都是唯一的,并且由于您在此处创建了唯一的复合键,因此两个主键的组合在整个表中必须是唯一的。

关于mysql - 关于sql插入日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36435367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com