开发者

creating a table with a primary key that is auto increment with default values of 10000

"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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜