質問編集履歴

2

DDL修正

2020/04/17 05:37

投稿

tera78
tera78

スコア9

test CHANGED
File without changes
test CHANGED
@@ -56,15 +56,15 @@
56
56
 
57
57
  hoge3 varchar(50) NOT NULL,
58
58
 
59
- hoge4 int NOT NULL COMMENT,
59
+ hoge4 int NOT NULL,
60
60
 
61
61
  hoge5 int NOT NULL,
62
62
 
63
63
  hoge6 varchar(255),
64
64
 
65
- hoge7 int NOT NULL COMMENT,
65
+ hoge7 int NOT NULL,
66
66
 
67
- hoge8 int NOT NULL COMMENT,
67
+ hoge8 int NOT NULL,
68
68
 
69
69
  hoge9 int NOT NULL,
70
70
 
@@ -130,13 +130,13 @@
130
130
 
131
131
  hoge21 varchar(255),
132
132
 
133
- hoge22 tinyint unsigned NOT NULL COMMENT,
133
+ hoge22 tinyint unsigned NOT NULL,
134
134
 
135
- hoge23 tinyint unsigned COMMENT,
135
+ hoge23 tinyint unsigned,
136
136
 
137
- hoge24 tinyint unsigned DEFAULT 0 NOT NULL COMMENT,
137
+ hoge24 tinyint unsigned DEFAULT 0 NOT NULL,
138
138
 
139
- hoge25 tinyint unsigned COMMENT,
139
+ hoge25 tinyint unsigned,
140
140
 
141
141
  hoge26 datetime NOT NULL,
142
142
 

1

DDLと発行したINSERT文です

2020/04/17 05:37

投稿

tera78
tera78

スコア9

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,163 @@
23
23
 
24
24
 
25
25
  恐らくAUTO_INCREMENTの採番値が更新されていなかったのだと思いますが、そのような事は発生するのでしょうか?また発生しやすい状況等ありましたらご教授頂くと幸いです。
26
+
27
+
28
+
29
+ **** 追記 ****
30
+
31
+ DDLとINSERT文です(※カラム名や値は変えています)
32
+
33
+ test2テーブルのINSERTで、AI_IDの重複でエラーになります。
34
+
35
+ ```
36
+
37
+ -- DDL
38
+
39
+ CREATE TABLE test
40
+
41
+ (
42
+
43
+ id int NOT NULL AUTO_INCREMENT,
44
+
45
+ hoge1 varchar(10) NOT NULL,
46
+
47
+ hoge2 varchar(10) NOT NULL,
48
+
49
+ datetime1 datetime NOT NULL,
50
+
51
+ datetime2 datetime NOT NULL,
52
+
53
+ datetime3 datetime NOT NULL,
54
+
55
+ datetime4 datetime NOT NULL,
56
+
57
+ hoge3 varchar(50) NOT NULL,
58
+
59
+ hoge4 int NOT NULL COMMENT,
60
+
61
+ hoge5 int NOT NULL,
62
+
63
+ hoge6 varchar(255),
64
+
65
+ hoge7 int NOT NULL COMMENT,
66
+
67
+ hoge8 int NOT NULL COMMENT,
68
+
69
+ hoge9 int NOT NULL,
70
+
71
+ datetime5 datetime NOT NULL,
72
+
73
+ datetime6 datetime NOT NULL,
74
+
75
+ PRIMARY KEY (id)
76
+
77
+ ) ENGINE = InnoDB;
78
+
79
+
80
+
81
+ CREATE TABLE test2
82
+
83
+ (
84
+
85
+ AI_ID int NOT NULL AUTO_INCREMENT,
86
+
87
+ id int NOT NULL,
88
+
89
+ id2 varchar(50),
90
+
91
+ hoge10 varchar(255) CHARACTER SET ascii,
92
+
93
+ hoge11 varchar(10),
94
+
95
+ hoge12 int,
96
+
97
+ datetime1 datetime NOT NULL,
98
+
99
+ datetime2 datetime NOT NULL,
100
+
101
+ PRIMARY KEY (AI_ID),
102
+
103
+ CONSTRAINT uq_test2_01 UNIQUE (id, id2, hoge10)
104
+
105
+ ) ENGINE = InnoDB;
106
+
107
+
108
+
109
+ CREATE TABLE test3
110
+
111
+ (
112
+
113
+ id2 varchar(50) NOT NULL,
114
+
115
+ hoge13 text NOT NULL,
116
+
117
+ hoge14 varchar(255) NOT NULL,
118
+
119
+ hoge15 tinyint unsigned,
120
+
121
+ hoge16 varchar(255),
122
+
123
+ hoge17 date,
124
+
125
+ hoge18 varchar(255),
126
+
127
+ hoge19 varchar(255),
128
+
129
+ hoge20 varchar(255),
130
+
131
+ hoge21 varchar(255),
132
+
133
+ hoge22 tinyint unsigned NOT NULL COMMENT,
134
+
135
+ hoge23 tinyint unsigned COMMENT,
136
+
137
+ hoge24 tinyint unsigned DEFAULT 0 NOT NULL COMMENT,
138
+
139
+ hoge25 tinyint unsigned COMMENT,
140
+
141
+ hoge26 datetime NOT NULL,
142
+
143
+ hoge27 datetime NOT NULL,
144
+
145
+ PRIMARY KEY (id2)
146
+
147
+ ) ENGINE = InnoDB;
148
+
149
+
150
+
151
+ ALTER TABLE test2
152
+
153
+ ADD FOREIGN KEY (id)
154
+
155
+ REFERENCES test (id)
156
+
157
+ ON UPDATE RESTRICT
158
+
159
+ ON DELETE RESTRICT
160
+
161
+ ;
162
+
163
+
164
+
165
+ ALTER TABLE test2
166
+
167
+ ADD FOREIGN KEY (id2)
168
+
169
+ REFERENCES test3 (id2)
170
+
171
+ ON UPDATE RESTRICT
172
+
173
+ ON DELETE RESTRICT
174
+
175
+ ;
176
+
177
+
178
+
179
+ -- INSERT文
180
+
181
+ insert into test2(id, id2, hoge10, hoge11, hoge12, datetime1, datetime2)
182
+
183
+ values(211, 'id2', 'hoge10', 'hoge11', null, NOW(), NOW());
184
+
185
+ ```