auto-increment

Is it guaranteed that numeric auto-incremented ID of new entity always bigger than existing IDs?

亡梦爱人 提交于 2019-12-02 02:26:14
问题 Is it guaranteed that auto-incremented ID of new entity always bigger than existing IDs ? Basically I want to periodically dump entity (e.g. Comment) in background task into big blobs as they get created by customers. So if there are 100 entities right now I'll store them in blob and create helper entity for this blob like class BlobRange { long fromId; // Comment.id long toId; // Comment.id String blobKey; } Next time background task would find biggest BlobRange.toId and would fetch new

Custom PrimaryKey Generation with autoincrement

隐身守侯 提交于 2019-12-02 01:44:26
问题 I need to define and generate primary key for 2 or more tables. Tables hold same type of data but FOR Some BUSINESS RULES we have to make them separate say like TableA = LOCAL_CUSTOMERS TableB = INTERNATIONAL_CUSTOMERS Both hold same columns like, CUSTOMER_ID C_NAME, CITY ....etc While designing the Primary Key I want these keys to be a combination of PREFIX and an auto generated number, as an auto increamented int PK will do. for example, CUSTOMER_ID (PK) for the table "LOCAL_CUSTOMERS" LOC1

Custom PrimaryKey Generation with autoincrement

假如想象 提交于 2019-12-02 01:22:28
I need to define and generate primary key for 2 or more tables. Tables hold same type of data but FOR Some BUSINESS RULES we have to make them separate say like TableA = LOCAL_CUSTOMERS TableB = INTERNATIONAL_CUSTOMERS Both hold same columns like, CUSTOMER_ID C_NAME, CITY ....etc While designing the Primary Key I want these keys to be a combination of PREFIX and an auto generated number, as an auto increamented int PK will do. for example, CUSTOMER_ID (PK) for the table "LOCAL_CUSTOMERS" LOC1, LOC2, LOC3,...... LOC5000 and CUSTOMER_ID (PK) for the table "INTERNATIONAL_CUSTOMERS" INT1, INT2,

When to fix auto-increment gaps in MYSQL

喜夏-厌秋 提交于 2019-12-02 00:03:43
The database I am working on right now has records being added and removed by the 10s of thousands and because of this there are gaps in the auto-incremented key hundreds of thousands big and auto-increment numbers well into the billions. These numbers are never stored to reference the individual record but are used to reference the record when doing on-the-fly calculations. Is there any reason to remove these gaps and reset the auto-increment number or is this inconsequential? The id field is an unsigned int, should I increase it to an unsigned big int? From what I understand, right now if it

Auto increment id JSON

佐手、 提交于 2019-12-01 23:33:23
I'm making a RESTful webservice and I want the items that are posted to the JSON file to have an Id. I've been searching everywhere but couldn't find anything on how to do this. The JSON looks like this [ { "id": "2", "title": "Hello World", "artist": "John Smith", "genre": "pop", "week": "4", "highest_rating": "3", "year": "2014", "youtube": "www", "links": [ { "rel": "self", "href": "" }, { "rel": "collection", "href": "" } ] }, { "id": "3", "title": "Lorem Ipsum", "artist": "John Smith", "genre": "pop", "week": "4", "highest_rating": "3", "year": "2014", "youtube": "www", "links": [ { "rel"

Auto-increment - automatic reset for each year

南笙酒味 提交于 2019-12-01 23:31:21
问题 MySQL/InnoDB In my case my receipts should be counted on yearly basis; 1/2015, 2/2015 ... 556/2015 and so on. When next year comes, the counter should start from 1 again and receipts should be counted as 1/2016, 2/2016 ... How to define auto_increment field which will reset itself on yearly basis? RCID | RCNO | RCYEAR | ... =====+======+========+==== 200 | 1 | 2015 | 201 | 2 | 2015 | ... | ... | 2015 | 756 | 556 | 2015 | <- last receipt in 2015 757 | 1 | 2016 | <- yearly counter restarted

Possible to condense primary key/serial?

本小妞迷上赌 提交于 2019-12-01 23:19:57
I have a database where everything is linked with foreign keys, so the Postgres knows exactly how the database is layed out.. Well, Lets say I have Table1 and Table2. Table1 has 3 fields. RID, table2_rid,data So table1.table2_rid references table2.RID and this is expressed with a foreign key. In both the RID field is the primary key and is a serial type. What I would like to know is how to "condense" the primary keys? Like say you add 5 records and deleted record number 3. Your primary keys would look like 1 2 4 5 Well, how do I get to update everywhere so that the primary key(and

mysql auto-increment on a non-primary key

孤街醉人 提交于 2019-12-01 21:57:32
Another question today :) This time I'd like to know if/how it's possible to make a second column auto-increment for each primary key: CREATE TABLE test ( `id` INTEGER UNSIGNED NOT NULL, `subId` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `text` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`, `subId`) ) ENGINE = InnoDB; This creation, unfortunately, doesn't work, only if I specify ID as primary key and subId as index key (but I need them both together and ID can repeat...) Example data (what I need): 1, 1 1, 2 1, 3 2, 1 2, 2 3, 1 The problem with making ID primary and subId index is that subId will

Autoincrement ID in App Engine datastore

廉价感情. 提交于 2019-12-01 20:55:23
I'm using App Engine datastore, and would like to make sure that row IDs behave similarly to "auto-increment" fields in mySQL DB. Tried several generation strategies, but can't seem to take control over what happens: the IDs are not consecutive, there seem to be several "streams" growing in parallel. the ids get "recycled" after old rows are deleted Is such a thing at all possible ? I really would like to refrain from keeping (indexed) timestamps for each row. Chris Calo It sounds like you can't rely on IDs being sequential without a fair amount of extra work. However, there is an easy way to

How can I automatically increment numbers in C#?

空扰寡人 提交于 2019-12-01 16:17:59
I am using C# 2008 Windows Forms application. In my project there is a TextBox control and in that I want make an auto generate numbers for samples s00, next when I come back to form again it should be increment like s01,s02,s03......like that Please help me Øyvind Bråthen Quite easy. Keep a variable to keep the current number. int incNumber = 0; Then on click of button, generate the number string like this: string nyNumber = "s" + incNumber.ToString("00"); incNumber++; Do as suggested by Øyvind Knobloch-Bråthen but if you want it to be done automatically when form is Deactivated and Activated