意外とやるミス
おっちょこちょいというか集中力がないというか、私はよくケアレスミスをするのでそのメモ。
その1
mysql> create table hoge ( -> id int autoincrement primary key -> hoge varchar(100) null, -> hogege varchar(100) not null, -> hogegege text, -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'autoi ncrement primary key, hoge varchar(100) null, hogege varchar(100) not n' at line 2
オートインクリメントの方法を調べず適当にやった結果。ミスは autoincrement 部分。正しくは
id int auto_increment primary key
のようにアンダースコアを入れなければいけない。
その2
さっきのをやったすぐ後のエラー
mysql> create table hoge ( -> id int auto_increment primary key -> hoge varchar(100) null, -> hogege varchar(100) not null, -> hogegege text, -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 6
なんでじゃーと思ったら閉じ括弧の前にコンマ (,) を入れていた。
これでエラーになるとは思わなかったので MySQL の融通の利かなさにちょっと感心した。
mysql> create table hoge ( -> id int auto_increment primary key -> hoge varchar(100) null, -> hogege varchar(100) not null, -> hogegege text -> ); Query OK, 0 rows affected (0.00 sec) mysql>
その後ちゃんと問題なく作成できた。