回答編集履歴
3
typo
test
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
|
19
19
|
create table tbl(id int not null primary key auto_increment
|
20
20
|
|
21
|
-
,uid int,name varchar(20),size in,hoge varchar(20)
|
21
|
+
,uid int,name varchar(20),size int,hoge varchar(20)
|
22
22
|
|
23
|
-
|
23
|
+
,unique key(uid,name,size));
|
24
24
|
|
25
25
|
```
|
26
26
|
|
2
調整
test
CHANGED
@@ -16,7 +16,11 @@
|
|
16
16
|
|
17
17
|
```SQL
|
18
18
|
|
19
|
-
create table tbl(id int not null primary key auto_increment
|
19
|
+
create table tbl(id int not null primary key auto_increment
|
20
|
+
|
21
|
+
,uid int,name varchar(20),size in,hoge varchar(20)
|
22
|
+
|
23
|
+
t,unique key(uid,name,size));
|
20
24
|
|
21
25
|
```
|
22
26
|
|
1
sample
test
CHANGED
@@ -5,3 +5,45 @@
|
|
5
5
|
であれば複合unique属性で「user_id,name,size」で
|
6
6
|
|
7
7
|
設定してみてはどうでしょうか?
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#sample
|
12
|
+
|
13
|
+
うまく動かないと言うのでsampleつけときます
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```SQL
|
18
|
+
|
19
|
+
create table tbl(id int not null primary key auto_increment,uid int,name varchar(20),size int,unique key(uid,name,size),hoge varchar(20));
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
順次データ投入
|
24
|
+
|
25
|
+
```SQL
|
26
|
+
|
27
|
+
insert into tbl(uid,name,size,hoge) values(1,'aaa',100,@a:='hoge1')
|
28
|
+
|
29
|
+
on duplicate key update hoge=@a;
|
30
|
+
|
31
|
+
insert into tbl(uid,name,size,hoge) values(1,'aaa',200,@a:='hoge2')
|
32
|
+
|
33
|
+
on duplicate key update hoge=@a;/*uidとnameが一緒だけどsizeが違うのでOK*/
|
34
|
+
|
35
|
+
insert into tbl(uid,name,size,hoge) values(1,'bbb',100,@a:='hoge3')
|
36
|
+
|
37
|
+
on duplicate key update hoge=@a;/*uidとsizeが一緒だけどnameが違うのでOK*/
|
38
|
+
|
39
|
+
insert into tbl(uid,name,size,hoge) values(1,'aaa',100,@a:='hoge4')
|
40
|
+
|
41
|
+
on duplicate key update hoge=@a;/*uidとsizeとnameが一緒なのでhogeを更新*/
|
42
|
+
|
43
|
+
insert into tbl(uid,name,size,hoge) values(2,'aaa',100,@a:='hoge5')
|
44
|
+
|
45
|
+
on duplicate key update hoge=@a;/*sizeとnameが一緒だけどuidが違うのでOK*/
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```
|