auto-increment

MSSQL Select statement with incremental integer column… not from a table

不羁的心 提交于 2019-11-27 15:45:53
问题 I need, if possible, a t-sql query that, returning the values from an arbitrary table, also returns a incremental integer column with value = 1 for the first row, 2 for the second, and so on. This column does not actually resides in any table, and must be strictly incremental, because the ORDER BY clause could sort the rows of the table and I want the incremental row in perfect shape always... Thanks in advance. --EDIT Sorry, forgot to mention, must run on SQL Server 2000 回答1: For SQL 2005

I need to auto_increment a field in MySQL that is not primary key

我是研究僧i 提交于 2019-11-27 15:37:17
问题 Right now, I have a table whose primary key is an auto_increment field. However, I need to set the primary key as username , date (to ensure that there cannot be a duplicate username with a date). I need the auto_increment field, however, in order to make changes to row information (adding and deleting). What is normally done with this situation? Thanks! 回答1: Just set a unique index on composite of (username, date). ALTER TABLE `table` ADD UNIQUE INDEX `name` (`username`, `date`);

Will MySQL reuse deleted ID's when Auto Increment is applied

偶尔善良 提交于 2019-11-27 14:41:42
问题 http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html That document I'm reading seems to say something like: "In this case (when the AUTO_INCREMENT column is part of a multiple-column index), AUTO_INCREMENT values are reused if you delete the row with the biggest AUTO_INCREMENT value in any group." I don't really understand what's being said there. Aren't the values supposed to be reused automatically? Thanks in advance... 回答1: InnoDB resets the auto_increment field when you

Create unique autoincrement field with mongoose

与世无争的帅哥 提交于 2019-11-27 14:19:37
Given a Schema: var EventSchema = new Schema({ id: { // ... }, name: { type: String }, }); I want to make id unique and autoincrement. I try to realize mongodb implementation but have problems of understanding how to do it right in mongoose. My question is : what is the right way to implement autoincrement field in mongoose without using any plugins and so on? Here is a good example of auto-incremented fields implementation using Mongoose: var CounterSchema = Schema({ _id: {type: String, required: true}, seq: { type: Number, default: 0 } }); var counter = mongoose.model('counter',

mysql Failed to read auto-increment value from storage engine

爱⌒轻易说出口 提交于 2019-11-27 14:19:35
I am having mysql table with one id field as auto-increment . When I insert values to the table am getting error as 1467 - Failed to read auto-increment value from storage engine Also the show table status shows me that the field with auto increment has 18446744073709551615 as Auto_increment value. What would be the issue can any one help me ....? Problem could absolutely be that: convert 18446744073709551615 to hex and you'll find $FFFF-FFFF-FFFF-FFFF . If your field is an unsigned 64bit you reach its limit. I had the same error but in my case I had about 1.5k records in the table. I fixed it

PostgreSQL: Auto-increment based on multi-column unique constraint

纵然是瞬间 提交于 2019-11-27 14:03:36
One of my tables has the following definition: CREATE TABLE incidents ( id serial NOT NULL, report integer NOT NULL, year integer NOT NULL, month integer NOT NULL, number integer NOT NULL, -- Report serial number for this period ... CONSTRAINT PRIMARY KEY (id), CONSTRAINT UNIQUE (report, year, month, number) ); How would you go about incrementing the number column for every report , year , and month independently ? I'd like to avoid creating a sequence or table for each ( report , year , month ) set. It would be nice if PostgreSQL supported incrementing " on a secondary column in a multiple

“Auto increment” alphabet in Java?

亡梦爱人 提交于 2019-11-27 11:46:43
"Auto increment" alphabet in Java - is this possible? From A to Z without a third-party library? Richie Yes, you can do it like this: for (char alphabet = 'A'; alphabet <= 'Z'; alphabet++) { System.out.println(alphabet); } It is also possible with typecasting: for (int i = 65; i <= 90; i++) { System.out.println((char)i); } Taylor Leese Yes, like this: for (int i = 0; i < 26; i++) { char upper = (char) ('A' + i); char lower = (char) ('a' + i); ... } for (char c = 'A'; c <= 'Z'; c++) { ... } Michel Gokan You are looking for something like this: for( int i = 'a'; i < 'z'; i++ ) System.out.println

How to force MySQL to take 0 as a valid auto-increment value

喜欢而已 提交于 2019-11-27 11:31:33
Long story short, I have a SQL file that I want to import as a skel style file, so this will be done repeatedly, programmatically. I can edit the SQL file however I want, but I'd rather not touch the application itself. This application uses userid = 0 to represent the anonymous user. It also has a relevant (blank) entry in the database to represent this 'user'. Hence, the line in my skel.sql looks something like this: INSERT INTO `{{TABLE_PREFIX}}users` VALUES (0, '', '', '', 0, 0, 0, '', '', 0, 0, 0, 0, 0, NULL, '', '', '', NULL); The problem with this is that uid is a auto_increment field,

What is the biggest ID number that autoincrement can produce in mysql

醉酒当歌 提交于 2019-11-27 10:15:37
问题 I have an database that is rapidly filled with data we talk about 10-20k rows per day. What is a limit of an ID with and autoincrement option? If ID is created as INTEGER then I can do max value of 2,147,483,647 for unsigned values? But what when autoincrement goes above this? Does it all collapses? What would be solution then? I am sure that a lot of people have big databases, and I would like to hear them. Thank you. 回答1: If you are worried about it growing out of bounds too quickly, I

Django BigInteger auto-increment field as primary key?

戏子无情 提交于 2019-11-27 09:47:45
问题 I'm currently building a project which involves a lot of collective intelligence. Every user visiting the web site gets created a unique profile and their data is later used to calculate best matches for themselves and other users. By default, Django creates an INT(11) id field to handle models primary keys. I'm concerned with this being overflown very quickly (i.e. ~2.4b devices visiting the page without prior cookie set up). How can I change it to be represented as BIGINT in MySQL and long(