回答編集履歴
1
sample
test
CHANGED
@@ -3,3 +3,43 @@
|
|
3
3
|
- set @num=0;update set 該当カラム=(@num:=@num+1) order by なんちゃら、としてユニークにし
|
4
4
|
|
5
5
|
- alter tableで当該カラムにuniqu属性をつける
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
# sample
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
- 仮データ作成
|
14
|
+
|
15
|
+
```SQL
|
16
|
+
|
17
|
+
create table tbl(val double);
|
18
|
+
|
19
|
+
insert into tbl values(rand()),(rand()),(rand()),(rand()),(rand());
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
- カラム追加
|
24
|
+
|
25
|
+
```SQL
|
26
|
+
|
27
|
+
alter table tbl add id int not null first;
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
- uniqueなidを投入
|
32
|
+
|
33
|
+
```SQL
|
34
|
+
|
35
|
+
update tbl set id=(select @a:=@a+1 from (select @a:=0) as dummy) order by val;
|
36
|
+
|
37
|
+
````
|
38
|
+
|
39
|
+
- unique属性追加
|
40
|
+
|
41
|
+
```SQL
|
42
|
+
|
43
|
+
alter table tbl add unique(id);
|
44
|
+
|
45
|
+
```
|