auto-increment

How to add auto increment primary key based on an order of column?

那年仲夏 提交于 2019-12-09 15:54:08
问题 I need to add an auto increment id to an already existing table. I did: ALTER TABLE table_name ADD column_name INT NOT NULL AUTO_INCREMENT FIRST , ADD PRIMARY KEY (column_name) However, the auto numbering wasnt based on any particular column order. I want mysql to smartly put auto numbers based on the order of certain column. Is it possible? Most of the answers out there tell you how to add auto increment fields, not how to control those numbers in already existing table. 回答1: Add a new field

Reference value of serial column in another column during same INSERT

こ雲淡風輕ζ 提交于 2019-12-09 02:48:16
问题 I have a table with a SERIAL primary key, and also an ltree column, whose value I want to be the concatenation of those primary keys. e.g. id | path ---------- 1 1 2 1.2 3 1.2.3 4 1.4 5 1.5 I'm curious if there's a way to do such an insert in one query, e.g. INSERT INTO foo (id, ltree) VALUES (DEFAULT, THIS.id::text) I'm probably overreaching here and trying to do in one query what I should be doing in two (grouped in a transaction). 回答1: You could use a subquery or a writable CTE to retrieve

using Notepad++ how can i make a macro type situation in which a number increments?

…衆ロ難τιáo~ 提交于 2019-12-09 02:12:36
问题 for example i have about 500 lines. in the beginning of each line i want to add a number. so in line 1 i would want "1)" and then line 2 i would want "2)" i know i can do a macro in n++, but it wouldn't be incremental. is there any possible way to do this? 回答1: Notepad++ Macros only playback keyboard actions. They can't do anything dynamic. However there is a built-in(?) plugin that can do this for you. Highlight all the code, then choose "TextFX / TextFX Tools / Insert Line Numbers" One

Auto Increment in Temporary Table

徘徊边缘 提交于 2019-12-08 12:30:53
问题 I'm trying to create a Temp Table that has a key field that auto increments. But I keep running into a syntax error. Here's what I'm trying: CREATE TEMPORARY TABLE RETURN_ARTISTS (KEY INT(11) NOT NULL AUTO_INCREMENT, ARTIST_1_KEY INT(11), ARTIST_2_KEY INT(11)); INSERT INTO RETURN_ARTISTS (1,1); DELETE TABLE RETURN_ARTISTS; And here's the error I keep getting: Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

auto increment - internal reference odoo9

本小妞迷上赌 提交于 2019-12-08 11:05:59
问题 I want to change the type of the field 'ref' (Internal Reference) to be auto incremented (for example every time I create a new contact my Internal Reference should increase by 1). So first contact should have Internal Reference 1, the second 2, the third 3 and so on... There are no errors but still the reference field is empty. Have I missed some additional code? Can someone help me? @api.model def create(self, vals): if vals.get('ref', 'New') == 'New': vals['ref'] = self.env['ir.sequence']

Why are there gaps in my IDENTITY column? [duplicate]

落花浮王杯 提交于 2019-12-08 07:29:28
问题 This question already has answers here : Why are there gaps in my IDENTITY column values? (7 answers) Closed 6 years ago . My table works fine if I enter data correctly - I can insert data and the IDENTITY values are 1, 2, 3, 4. However, if I make a mistake and get an error message, e.g. Cannot insert the value NULL into column 'x', table 'table'; column does not allow nulls. INSERT fails. The statement has been terminated. Then if I insert another row successfully, the IDENTITY value is 6,

Auto-incrementation with HSQLDB (2.2.8) + DDLUtils

我只是一个虾纸丫 提交于 2019-12-08 06:35:49
问题 I want to use HSQLDB as an embedded database but am having trouble getting it to auto-increment . As far as I understand, [CALL] IDENTITY() can be used to get the last primary key value. However, experiments through both iBatis and HSQLDB's DatabaseManagerSwing continually return a 0 value. How can I get auto-incrementation to work with HSQLDB? Edit: I didn't mention that I'm using DDLUtils to autogenerate tables. The following does not suit HSQLDB: <?xml version="1.0"?> <!DOCTYPE database

Update Query with LEFT JOIN , Variable and Autoincrement Using MySQL

最后都变了- 提交于 2019-12-08 05:52:46
问题 I am stuck on a situation. Here is the table structures. default_category category_id | parent_id | name | symbol ----------------------------------------------------------- 1 | 1 | SMT Equipment | SMT 2 | 1 | ATE & INSPECTION | ATE 3 | 1 | Feeders | FED 4 | 1 | Rework Station | RWS 5 | 1 | X-Ray Machines | XRM default_products id | subcategory_id | product_name | product_code --------------------------------------------------- 1 | 1 | A | null 2 | 1 | B | null 3 | 2 | C | null 4 | 2 | D |

How to increment an auto-increment field with ADO.NET in C#

故事扮演 提交于 2019-12-08 03:56:53
问题 I have a database table with three fields: Product(ProdId, Name, Price) Where ProdId is a auto-increment field. The auto-increment is with seed 1, starting from 0. I perform operation on the database by using C# in an ASP.NET application. If I use LINQ to INSERT a new record I just assign values to Name and Price fields and when I submit the changes the database is responsible to increment the ProdId. How can I do it with the standard ADO.NET? If I write an INSERT statement INSERT INTO

Automatically set mysql autoincrement to min value

混江龙づ霸主 提交于 2019-12-08 03:20:29
问题 i just wondered, if there is an elegant way of automatically resetting the autoincrement of a mysql table to the lowest value according to the present content. example: mytable: 1 content of row 1 2 content of row 2 3 content of row 3 4 content of row 4 5 content of row 5 now the autoincrement will be at 6 but before i insert new contents, i delete row 3,4 and 5. the content would look like this: 1 content of row 1 2 content of row 2 the autoincrement would still be at 6. and this is the