"CREATE TABLE dummy
(
tnum UNSIGNED INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (tnum),
)";
ALTER TABLE dummy AUTO_INCREMENT = 10000;
This is not running. I would like to know what causes the error, and alternatives so that I can create an auto-incrementing primary key has a de开发者_如何转开发fault value of 10000.
Unsigned is great for AUTO_INCREMENT columns! It gives you twice as many possible values!
Change your query to the following:
CREATE TABLE dummy (
tnum INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
) AUTO_INCREMENT=10000
Remove the unsigned
, the "
(both the double quotes) and ',' (comma) after PRIMARY KEY (tnum),
CREATE TABLE dummy
(
tnum INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (tnum)
);
ALTER TABLE dummy AUTO_INCREMENT = 10000;
It works.
If you need to set auto_increment start value, you can use this code:
CREATE TABLE dummy
(
tnum INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (tnum)
) AUTO_INCREMENT=10000;
that is because you can't have an auto increment and a default value at the same time, the value will increment for every new entry.
It looks more like you are having a php error to me, show some code in your php file, The section that is performing the query is not correct,
Make sure you have matching single quotes or double quotes. and remember yu can only do one query at a time.
use the command line or an application like mysql workbench to create and manipulate your db
delimiter $$
CREATE TABLE `dummy` (
`tnum` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`tnum`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=latin1$$
If you are copying and pasting it from somewhere, beware, any special/non-ascii char will result in error
Remove UNSIGNED
from your query.
精彩评论