English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to create a table named "user" in mysql with the follwing command :
mysql>CREATE TABLE user ( usernumber mediumint(10) DEFAULT '0' NOT NULL AUTO_INCREMENT , userid VARCHAR(8) BINARY NOT NULL, userpassword VARCHAR(20) BINARY NOT NULL, PRIMARY KEY (userid), UNIQUE usernumber (usernumber)); the error messege it is giving is ERROR 1067(42000): invalid default value for 'usernumber'

2007-02-21 02:05:31 · 3 answers · asked by tejaswi sharma 1 in Computers & Internet Programming & Design

3 answers

You have the default for usernumber in quotes which denotes it as a string. Try removing the single quotes from around the zero.

2007-02-21 02:09:24 · answer #1 · answered by Mark B 5 · 0 0

The error is very simple that ... if ur assiging a value to a field which is a string then it should be in (' ') where as if u r assigning a value for an integer type it should be without ('') .. i had Rewritten the code check this out ...

CREATE TABLE user ( usernumber mediumint(10) DEFAULT 0 NOT NULL AUTO_INCREMENT , userid VARCHAR(8) BINARY NOT NULL, userpassword VARCHAR(20) BINARY NOT NULL, PRIMARY KEY (userid), UNIQUE usernumber (usernumber))


Thanks
Suraj Sharma

2007-02-21 02:11:19 · answer #2 · answered by suraj s 2 · 0 0

usernumber mediumint(10) DEFAULT '0' NOT NULL AUTO_INCREMENT

AUTO_INCREMENT remplace the DEFAULT value
the first row insert will be set to DEFAULT '0'
the second row insert will be set to DEFAULT '1'
the third row insert will be set to DEFAULT '2'
......
you can't use DEFAULT and AUTO_INCREMENT in the same field
use this instead :

usernumber mediumint(10) NOT NULL AUTO_INCREMENT

2007-02-21 02:12:50 · answer #3 · answered by apoorlonesomegeek 2 · 1 0

fedest.com, questions and answers