auto-increment

mysql ID auto increment doesn't starts from 0

China☆狼群 提交于 2019-12-03 11:07:23
i have a table with ID , this ID is auto increment and primary key ,the first time i inserted to that table , the ID starts from 0 , but after i removing all the values from that table and inserted again to it , the ID doesn't start from 0 , but starts from the last value that ID had , what is going wrong please ? can i reset the value to 0 ? You may either truncate the table using TRUNCATE `table` Truncate will delete all of the data in the table. Note that using TRUNCATE will also not fire any DELETE triggers like DELETE . Or you can reset the count using ALTER TABLE `table` AUTO_INCREMENT =

How do I change the Auto Increment counter in MySQL?

最后都变了- 提交于 2019-12-03 10:35:33
问题 I have an ID field that is my primary key and is just an int field. I have less than 300 rows but now every time someone signs up that ID auto inc is inputted really high like 11800089, 11800090, etc.... Is there a way to get that to come back down so it can follow the order (310,311,312) . Thanks! 回答1: ALTER TABLE tbl AUTO_INCREMENT=310; Beware though, you don't want to repeat an ID. If the numbers are that high, they got that way somehow. Be very sure you don't have associated data with the

PHP short unique ID generation using auto_increment?

旧街凉风 提交于 2019-12-03 09:57:20
问题 I would like to generate a short, unique ID without having to check for collisions. I currently do something like this, but the ID I currently generate is random and checking for collisions in a loop is annoying and will get expensive if the number of records grows significantly. Normally worrying about collisions isn't an issue, but the unique ID I want to generate is a short unique string 5-8 characters, alpha-numeric, like tinyurl does. EDIT: I would like to start out with 5 characters and

SQL - Check if a column auto increments

孤街醉人 提交于 2019-12-03 08:35:57
问题 I am trying to run a query to check if a column auto increments. I can check type, default value, if it's nullable or not, etc. but I can't figure out how to test if it auto increments. Here is how I am testing for those other things: SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'my_table' AND COLUMN_NAME = 'my_column' AND DATA_TYPE = 'int' AND COLUMN_DEFAULT IS NULL AND IS_NULLABLE = 'NO' --AND AUTO_INCREMENTS = 'YES' Unfortunately there is no AUTO_INCREMENTS column to compare

How to insert new row to database with AUTO_INCREMENT column without specifying column names?

允我心安 提交于 2019-12-03 05:35:59
I have a table with the following columns: id - INT UNSIGNED AUTO_INCREMENT name - VARCHAR(20) group - VARCHAR(20) I know that I can add a row like this: INSERT INTO table_name (name, group) VALUES ('my name', 'my group') I wonder if there is a way to add a row without specifying the column names , like when there is no AUTO_INCREMENT column ? Ike Walker For some databases, you can just explicitly insert a NULL into the auto_increment column: INSERT INTO table_name VALUES (NULL, 'my name', 'my group') Even better, use DEFAULT instead of NULL. You want to store the default value, not a NULL

How can I avoid getting this MySQL error Incorrect column specifier for column COLUMN NAME?

断了今生、忘了曾经 提交于 2019-12-03 05:23:10
How can I avoid getting this MySQL error Incorrect column specifier for column topic_id ? MySQL Error... #1063 - Incorrect column specifier for column 'topic_id' SQL Schema... CREATE TABLE discussion_topics ( topic_id char(36) NOT NULL AUTO_INCREMENT, project_id char(36) NOT NULL, topic_subject VARCHAR(255) NOT NULL, topic_content TEXT default NULL, date_created DATETIME NOT NULL, date_last_post DATETIME NOT NULL, created_by_user_id char(36) NOT NULL, last_post_user_id char(36) NOT NULL, posts_count char(36) default NULL, PRIMARY KEY (topic_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO

Auto increment a value in Django with respect to the previous one

好久不见. 提交于 2019-12-03 03:27:57
Is there a way to autoincrement a field with respect to the previous one...e.g if the previous record has the value 09-0001, then the next record should be assigned 09-0002 and so one...ideas? I'm thinking of overriding the save method, but how exactly I'm not so sure Django won't let you have more than one AutoField in a model, and you already have one for your primary key. So you'll have to override save and will probably need to look back at the table to figure out what to increment. Something like this: class Product(models.Model): code = models.IntegerField() number = models.IntegerField(

SQL GUID Vs Integer

徘徊边缘 提交于 2019-12-03 02:20:29
I have recently started a new job and noticed that all the SQL tables use the GUID data type for the primary key. In my previous job we used integers (Auto-Increment) for the primary key and it was a lot more easier to work with in my opinion. For example, say you had two related tables; Product and ProductType - I could easily cross check the 'ProductTypeID' column of both tables for a particular row to quickly map the data in my head because its easy to store the number (2,4,45 etc) as opposed to (E75B92A3-3299-4407-A913-C5CA196B3CAB). The extra frustration comes from me wanting to

Compact or renumber IDs for all tables, and reset sequences to max(id)?

牧云@^-^@ 提交于 2019-12-03 01:18:08
After running for a long time, I get more and more holes in the id field. Some tables' id are int32, and the id sequence is reaching its maximum value. Some of the Java sources are read-only, so I cannot simply change the id column type from int32 to long , which would break the API. I'd like to renumber them all. This may be not good practice, but good or bad is not concerned in this question. I want to renumber, especially, those very long IDs like "61789238", "548273826529524324". I don't know why they are so long, but shorter IDs are also easier to handle manually. But it's not easy to

currval has not yet been defined this session, how to get multi-session sequences?

本小妞迷上赌 提交于 2019-12-03 01:12:15
My objective is to get a primary key field automatically inserted when inserting new row in the table. How to get a sequence going from session to session in PostgreSQL? doubleemploi@hanbei:/home/yves$ psql -d test Mot de passe : psql (8.4.13) Saisissez « help » pour l''aide. test=> create sequence test001 start 10; CREATE SEQUENCE test=> select currval('test001'); ERREUR: la valeur courante (currval) de la séquence « test00 » n''est pas encore définie dans cette session --- current value not yet defined this session (???) test=> select setval('test001', 10); setval -------- 10 (1 ligne) test=