Badtant Posted July 21, 2004 Share Posted July 21, 2004 hej! kan man på något sätt ställa in att "auto increment" ska börja på typ 1000 istället för 1? hoppas det... /niklas Link to comment Share on other sites More sharing options...
fhe Posted July 21, 2004 Share Posted July 21, 2004 kan man på något sätt ställa in att "auto increment" ska börja på typ 1000 istället för 1? Ja, men hur man gör beror på vad man har för tabeller: Så här står det på http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html AUTO_INCREMENT The initial AUTO_INCREMENT value for the table. This works for MyISAM only. To set the first auto-increment value for an InnoDB table, insert a dummy row with a value one less than the desired value after creating the table, and then delete the dummy row. Vilket alltså innebär att om du kör MyISAM så kan du göra så här: [color="#0000ff"]CREATE TABLE[/color] habla (nyckel int NOT NULL auto_increment, slask varchar(20), PRIMARY KEY(nyckel)) AUTO_INCREMENT=1000 TYPE=MyISAM; Medans du med InnoDB-tabller måste göra: [color="#0000ff"]CREATE TABLE[/color] habla (nyckel int NOT NULL auto_increment, slask varchar(20), PRIMARY KEY(nyckel)) TYPE=InnoDB; [color="#0000ff"]INSERT[/color] INTO habla (999, [color="#ff0000"]'dummy'[/color]); [color="#0000ff"]DELETE[/color] [color="#0000ff"]FROM[/color] habla [color="#0000ff"]WHERE[/color] nyckel=999; (koden ovan otestad men den borde fungera om jag inte gjort nåt typo) Link to comment Share on other sites More sharing options...
fhe Posted July 22, 2004 Share Posted July 22, 2004 [color="#0000ff"]INSERT[/color] INTO habla (999, [color="#ff0000"]'dummy'[/color]); Borde inte INTO vara blått förresten? Link to comment Share on other sites More sharing options...
drisse Posted April 6, 2009 Share Posted April 6, 2009 To start with an AUTO_INCREMENT value other than 1, you can set that value with CREATE TABLE or ALTER TABLE, like this: mysql> ALTER TABLE tbl AUTO_INCREMENT = 100; Link to comment Share on other sites More sharing options...
Jonas__B Posted April 7, 2009 Share Posted April 7, 2009 22 juli 2004 20:54 Rätt gammal tråd men bra att du är aktiv! [inlägget ändrat 2009-04-07 09:01:34 av Jonas_Bo] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.