auto-increment

Get all inserted IDs when inserting multiple rows using a single query

左心房为你撑大大i 提交于 2019-12-01 15:24:40
I've already looked at other answers and I still feel that my question is relevant and deserves a separate entry. I have a table named settings(which stores user settings) and I have to insert multiple settings for each user. Initially, I had executed a separate insert statement for each setting, but having felt this wasn't a particularly good way to do it, I thought of inserting multiple rows by the same insert statement. My only problem is that I want the auto_incremented IDs of each of the newly inserted rows. I've read answers that say this isn't possible/scalable etc, but I feel that I

How can I automatically increment numbers in C#?

三世轮回 提交于 2019-12-01 15:00:40
问题 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 回答1: 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++; 回答2: Do as suggested by Øyvind

composite (alphanumeric) primary key and auto increment

╄→尐↘猪︶ㄣ 提交于 2019-12-01 14:26:59
Is it possible to make an auto-increment function in MySQL that combines alpha elements and numeric? I have an existing system with keys like QAb99, QAb101, QAd9003, etc. The max numeric portion ranges from 1 to 9999, while the letters begin with QA and range from QAa to QAd, etc. and will eventually pass QAd9999 to QAe1, etc. Is it better to manage generating new keys in SQL or outside of SQL (i.e. php script)? thanks. I asked this a while ago. Mysql doesn't do this unfortunately. I'd love it to, but it just doesn't. In php you could do it. Example: public function random_id_gen($length) { /

How to increment alphanumeric number in android? [closed]

橙三吉。 提交于 2019-12-01 13:39:20
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I'm new to android coding practice ABB20180001 Suppose this as my first id, and i wish to auto-increment this by 1 using shared preferences and use as employee id. like ABB20180002, ABB20180003, ABB20180004 etc. 回答1: You can't increment alphanumeric values directly. if want to do so

Auto-increment field that resets after a change in another field

假装没事ソ 提交于 2019-12-01 12:51:06
Can you provide a very simple SQL example of how to create a "count" or "order" field that would auto-increment, but restart after every change in a different field? In the table below, the "Order" field would restart at "1" every time there was a change in the "Meal" field. Thanks. Meal Time Order Lunch 10:30 1 Lunch 11:00 2 Lunch 11:15 3 Dinner 4:30 1 Dinner 4:45 2 Dinner 5:00 3 Dinner 5:30 4 Instead of storing Order in the table, consider adding it to a view. You can select from the view instead of the table when you need it. The view could use row_number() to calculate the order, like:

Increment value of a table ID for each INSERT

淺唱寂寞╮ 提交于 2019-12-01 11:54:24
问题 I'm using PostgreSQL with all my tables setup. I currently have a table called comments with a primary key called comment_id which is a VARCHAR of length 4. I have a form setup to insert a new comment into the database but I'm confused as to how I will get my Java servlet to ++ the comment_id from it's previous value. E.g. 0001 to 0002. 回答1: You don't want to use a VARCHAR for your id column. In postgres you can create a sequence and then get the next value of that sequence for each insert.

Auto-increment field that resets after a change in another field

浪尽此生 提交于 2019-12-01 09:48:48
问题 Can you provide a very simple SQL example of how to create a "count" or "order" field that would auto-increment, but restart after every change in a different field? In the table below, the "Order" field would restart at "1" every time there was a change in the "Meal" field. Thanks. Meal Time Order Lunch 10:30 1 Lunch 11:00 2 Lunch 11:15 3 Dinner 4:30 1 Dinner 4:45 2 Dinner 5:00 3 Dinner 5:30 4 回答1: Instead of storing Order in the table, consider adding it to a view. You can select from the

Re-Indexing MySQL INT Primary Keys & Reset AUTO_INCREMENT

不打扰是莪最后的温柔 提交于 2019-12-01 09:18:27
So I have a MySQL database that I'm using with a PHP site. Over the course of weeks of development, I'm left with something like: Table: users id | name ----------- 12| Bob 34| Jen 155| John 154| Kyle Except this goes on for hundreds of records and the ids are in the thousands. I'm looking for a script I can run to re-name the keys to their lowest value (preserving their respective rows), and then reset the AUTO_INCREMENT to the next id The desired output would be: Table: users id | name ----------- 1| Bob 2| Jen 3| Kyle 4| John And ALTER TABLE users AUTO_INCREMENT = 5; (Notice Kyle and John )

change auto_increment within same table using subquery mysql

北慕城南 提交于 2019-12-01 08:37:08
I am using mysql. I have a database table with auto_increment counter set. Now because of a requirement I need to leave starting 100 ids free and move all existing records starting from 101, so current id 1 will go to 101 and id 2 will become 102 and so on. I am able to move records to 101 but the problem is that how to change auto_increment counter to max(id)+1. Main constraint here with me is that I need to do it in single sql statement. I can not save the value using @counter and use it later. I tried using below query ALTER TABLE role AUTO_INCREMENT = (SELECT rd.counter FROM (SELECT (MAX

auto-increment using loopback.js and MongoDB

泄露秘密 提交于 2019-12-01 08:37:01
i want to increase mongodb document number automatically using loopback. I made function in mongo function getNextSequence(name) { var ret = db.counters.findAndModify( { query: { _id: name }, update: { $inc: { seq: 1 } }, new: true } ); return ret.seq; } db.tweet.insert( { "_id" : getNextSequence("userid"), "content": "test", "date": "1", "ownerUsername": "1", "ownerId": "1" } ) It is working in mongo shell. However when I insert using loopback.js browser ( http://localhost:3000/explorer/ ), It is not working. 400 error(SytaxError) code is showing. I can not use mongo function in loopback rest