Solved

how to set auto increment = 1

Posted on 2011-09-21
2
456 Views
Last Modified: 2012-05-12
Experts,

if i run the following scripts i still get three records with id = 10, 20, and 30. What am I missing here?

i'm completely new to mySQL, but this is odd...

drop table admin_users;

CREATE TABLE `admin_users` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `admin_logon` varchar(32) NOT NULL,
  `admin_psswd` varchar(32) NOT NULL,
  `update_psswd` int(11) NOT NULL DEFAULT '0',
  `dept_id` int(11) NOT NULL,
  `role_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM;

alter table admin_users auto_increment = 1;

INSERT INTO `admin_users`
(`admin_logon`,
`admin_psswd`,
`update_psswd`,
`dept_id`,
`role_id`)
VALUES
('dduck','test',0,4,2);

INSERT INTO `admin_users`
(`admin_logon`,
`admin_psswd`,
`update_psswd`,
`dept_id`,
`role_id`)
VALUES
('mmouse','test',0,4,2);

INSERT INTO `admin_users`
(`admin_logon`,
`admin_psswd`,
`update_psswd`,
`dept_id`,
`role_id`)
VALUES
('pluto','test',0,4,2);

select * from admin_users;

Result:

ID

10      2011-09-21 04:09:39      dduck      test      0      4      2
20      2011-09-21 04:09:39      mmouse      test      0      4      2
30      2011-09-21 04:09:40      pluto      test      0      4      2

TIA!
0
Comment
Question by:crafuse
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 36572420
Check to see the seed value of the autoincrement isn't set to 10.

You can check by:

SELECT Auto_increment FROM information_schema.tables WHERE table_name='the_table_you_want';

 As noted elsewhere you can change by using the system variable @@set_auto_increment_increment

SET @@auto_increment_increment=1;

refer
http://stackoverflow.com/questions/206751/mysql-autoincrement-column-jumps-by-10-why
0
 

Author Closing Comment

by:crafuse
ID: 36572461
thanks, ya i found that too...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now