0
CREATE TABLE IF NOT EXISTS `qdz76_piteachers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `teacher_name` varchar(250) NOT NULL,
  `teacher_alias` varchar(250) NOT NULL,
  `teacher_role` varchar(50) NOT NULL,
  `image_folderlrg` int(11) NOT NULL,
  `teacher_image_lrg` varchar(250) NOT NULL,
  `teacher_email` varchar(100) NOT NULL,
  `teacher_website` varchar(250) NOT NULL,
  `teacher_description` text NOT NULL,
  `published` tinyint(3) NOT NULL,
  `ordering` int(11) NOT NULL,
  `teacher_view` tinyint(3) NOT NULL,
  `checked_out` tinyint(1) NOT NULL DEFAULT '0',
  `checked_out_time` datetime DEFAULT NULL,
  `user` int(11) NOT NULL,
  `language` char(7) NOT NULL DEFAULT '*',
  `featured` tinyint(3) NOT NULL DEFAULT '0',
  `metakey` text NOT NULL,
  `metadesc` text NOT NULL,
  `lastname` varchar(250) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=30 ;

I am very new to mysql and have read this page http://dev.mysql.com/doc/refman/5.5/en/create-table.html, it looks like AUTO_INCREMENT = 30 is in table_option section, but I still don't understand what AUTO_INCREMENT = 30 here means. Does it mean all int fields have auto_increment as 30?

shenkwen
  • 3,536
  • 5
  • 45
  • 85
  • No this seems like the dump of an existing table. The number 30 is the last auto increment ID used on that table. – e4c5 Sep 22 '15 at 04:43
  • This is from a .sql file which was exported from an existing table, now that you mention it, I notice that it has 30 entries. But how did you know it is "like the dump of an existing table"? And if we ignore the background story, how does `AUTO_INCREMENT = 30` affect the would-be created table? – shenkwen Sep 22 '15 at 04:47
  • 1
    Well the create statement having the AUTO_INCREMENT=x parameter is usually an indication that it came from a dump. Having it means when you insert data into that table again the next auto increment number will be 31. This prevents a collision in case you decide to import the old table data as well (which is usually the case) – e4c5 Sep 22 '15 at 04:49
  • Totally agree with e4c5; The number 30 is the last auto increment ID used on that table – Chintan7027 Sep 22 '15 at 04:54

1 Answers1

0

Actually whenever you prepare a dump from server or get table structure from phpmyadmin then it provide you auto_increment value as per existing table values, so you will be getting it as 30.

Whenever you create new table, then no need to mention auto_increment (if there is no specific reason) as it automatically start from 1.

In some specific reason you need to tell mysql that my auto_increment value should start from this number in this case you need to specify it in your table creation syntax.

Zafar Malik
  • 6,734
  • 2
  • 19
  • 30