auto-increment

How to auto increment id with a character

醉酒当歌 提交于 2019-12-16 18:02:28
问题 How do I auto-increment an ID of a member in my table together with a character with it for example: M_01 , M_02 , M_03 : CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); 回答1: The answer is: Don't. Use a basic serial column. You can always format the column on output. A sensible table definition could look like this (added more suggestions): CREATE TABLE company( company_id serial PRIMARY KEY , birth_year int NOT NULL ,

How to find next free unique 4-digit number

大兔子大兔子 提交于 2019-12-14 03:43:08
问题 In my db application I have a requirement for a unique, 4-digit number field for each customer. Up until 9999 I can just use autoincrements, but after that I will have to reuse numbers of customers that have been deleted (there won't be more than 5000 customers at a given time but there may be more than 9999 customers over the lifetime of the system). Question 1: Is there a (My)SQL statement to find the next reusable free number? Question 2: If I get the number, assign it to a new customer

I want to reuse the gaps of the deleted rows

ε祈祈猫儿з 提交于 2019-12-14 03:35:47
问题 I have a auto-increment primary key on one of my tables. If I have 3 rows and, for example, delete the third row I'm left with two. However, if I insert a new row its ID is automatically 4 and the IDs are 1, 2 and 4. How can I re-use the deleted ID and have the ID of the newly inserted record to be 3 automatically? 回答1: Really, you shouldn't. Primary keys should be purely technical, meaningless values. Their value, and the monotony of the generation, shouldn't matter at all. Moreover, since

How to block auto_increment to set the next number always as maxnumber + 1

萝らか妹 提交于 2019-12-14 03:22:23
问题 I have a table with auto_incremented field. The way normally auto increment works is it always start with the max value + 1. For e.g. if I insert two records, auto increment field takes 1 and 2 as the value initially. Now when I add a third row by explicitly mentioning the id field value as 100. After this, If I add a fourth record, auto increment value will be 101, not 3. My Question : Is there any way in mysql to enforce auto increment to follow its series? If it encounters a duplicate, it

how to set H2 primary key id to auto_increment?

隐身守侯 提交于 2019-12-14 00:48:42
问题 i am using sql, H2, and i am trying to make so that the ID of Usertable is auto_incremented. i tried all sql commands in H2 sql interface, didnot work out. alter table user alter column int not null auto_increment; this common one is even not working. is there any annotation of JPA for auto_incement may be? thanks a lot 回答1: You should use the JPA annotations @Id and @GeneratedValue for your ID. Your SQL looks valid. Can you post the error message? 回答2: I had the same problem. I am not sure

How do I get Id of a record without submitting and re-querying?

时光毁灭记忆、已成空白 提交于 2019-12-14 00:42:01
问题 I have an ID that is set to auto increment (int obviously). var dc = new DataContext([STRING]); var usersTable = dc.GetTable<Audit_User>(); var user = usersTable.FirstOrDefault(o => o.Username.Equals("NAME")); if (user == null) { user = new Audit_User() { Username = "NAME" }; usersTable.InsertOnSubmit(user); } //HERE - I need access to the user Id dc.SubmitChanges(); For more context, please see the tags. 回答1: //HERE - I need access to the user Id Actually you do not . If you consistently use

dynamically change the auto-increment in mysql

允我心安 提交于 2019-12-13 23:10:35
问题 I have a form that adds some data to a table.and i have a php file that prints out the data.in this page in each row a link is printed that when you click on it you will proceed to a page that deletes that single row. this page is called delete.php but there is a problem:when a single row is deleted , if i add another row , the auto-increment will be printed wrong! fow example if you delete row 7 and there are 13 rows printed,when you add another row the printed auto-increment column will be

Creating Auto Incrementing column in Google Appengine

青春壹個敷衍的年華 提交于 2019-12-13 17:17:55
问题 What is the easiest and most efficient way to create an auto-increment counter for every data row in google appengine? basically I want to give every row a unique row_number so that I can overcome the issue of only being able to get the first 1000 results in a select query. I can thus add a counter lies between condition and mine all the entires in the table. 回答1: You don't need to keep track of row numbers, you can use cursors instead. For Java see: http://code.google.com/appengine/docs/java

MYSQL & innoDB alter dynamically AUTO_INCREMENT of a table

时光总嘲笑我的痴心妄想 提交于 2019-12-13 13:04:07
问题 I have a problem, for example in my system I have the next table: CREATE TABLE `sales` ( `id` int(11) NOT NULL AUTO_INCREMENT, `amount` FLOAT NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; -- is more complex table With content: +-----+-------+ | id | amount| +-----+-------+ |2023 | 100 | |2024 | 223 | |2025 | 203 | |... | |2505 | 324 | +-----+-------+ I don't know the current id(There are sales every day). I'm trying to normalize the table. UPDATE sales SET id=id - 2022; Result: +-----+-------

Faking Auto Increment Increment on a Table in MySQL Using Trigger

时光怂恿深爱的人放手 提交于 2019-12-13 07:45:32
问题 I have a content table in my MySQL database (a Drupal content table, for what it's worth), which has an auto incremented primary key, nid. I want to be able to implement an odd and even id solution, where content created on production has even ids and content created on dev has odd ids, to avoid id conflicts when I sync. Unfortunately, MySQL doesn't support sequences, or per-table auto increment increment values (i.e. increment by 2 only for db.node, rather than 1). The best solution I can