Quantcast
Channel: Toad for MySQL
Viewing all articles
Browse latest Browse all 1315

Forum Post: Error with ZEROFILL on AUTOINCREMENT Column

$
0
0
Hi.  First post!  Thanks for the software.  Much better looking and user friendly UI than others I've tried. QUESTION Is it possible to ZEROFILL an AUTOINCREMENT column? AIM For data entry directly in Toad, I would ideally like values in the id column to appear padded with zeros to 4 places (eg 0001, 0002 etc). I understand that ZEROFILL is the way to do this, in conjunction with the length parameter (stated in parentheses after INT). The column in question is the table's surrogate primary key. The database is an InnoDB development database. APPROACH I'm using Toad for MySQL's "Alter Tables" form, "Columns" tab to alter the existing id column. The properties I selected in the form are listed in a table below. (I tried to insert the table here, but text that should appear beneath it was displayed beside it, probably due to HTML floats and block elements versus inline elements.) Toad for MySQL generates SQL from the settings on the form. This is the query it generated (attempt 1): ALTER TABLE database.table  CHANGE col_id col _id INT(4) AUTO_INCREMENT  ZEROFILL NOT NULL; When I also tried explicity requesting an unsigned integer, Toad produced this query (attempt 2): ALTER TABLE database.table  CHANGE col _id col _id INT(4) UNSIGNED AUTO_INCREMENT  ZEROFILL NOT NULL; Incidentally, it was generated exactly as shown, including the line breaks etc. ERROR When I click OK (with either set of settings), I receive the following error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ZEROFILL NOT NULL' at line 2" So I have to cancel the operation. TROUBLESHOOTING Are zerofills allowed on an autoincrement column?  If not, it would be handy if Toad's form indicated that. Is the autogenerated whitespace ok? Is the autogenerated SQL syntax correct? Are the keywords in the right sequence? The syntax / sequence that the person who wrote this code [ http://pastebin.com/15WsFpww ] used was: col_id INT(4) ZEROFILL NOT NULL AUTO_INCREMENT ; as opposed to: col_id INT(4) AUTO_INCREMENT ZEROFILL NOT NULL; Is it significant that the autogenerated SQL does not mention that the column is the primary key, despite it being stated on the "General" tab of Toad's alter table form. ASIDE Is ZEROFILL particular to Toad?  I don't see it mentioned in the official MySQL documentation. THANKS Thanks in advance. FORM SETTINGS Properties Attempt 1 Attempt 2 Common (name) column_id column_id Comment Datatype INT INT Default Value Length 4 4 Not Null True True Numerical Auto Increment True True Unsigned False True Zero Fill True True

Viewing all articles
Browse latest Browse all 1315

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>