auto-increment

auto-increment using loopback.js and MongoDB

ε祈祈猫儿з 提交于 2019-12-01 07:06:23
问题 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

JPA or Hibernate to generate a (non primary key) column value, not starting from 1

ⅰ亾dé卋堺 提交于 2019-12-01 06:32:20
问题 I want a JPA/Hibernate (preferably JPA) annotation that can generate the value of a column, that is not a primary key and it doesn't start from 1. From what I have seen JPA cannot do that with @GeneratedValue and @SequenceGenerator and @TableGenerator. Or with anything else. I have seen a solution with an extra table, which I find is not elegant. I can live with a Hibernate annotation, because I already have hibernate annotations. I want to use @Generated but I cannot make it work and people

change auto_increment within same table using subquery mysql

你说的曾经没有我的故事 提交于 2019-12-01 06:10:35
问题 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

How do I add auto_increment to a column in SQL Server 2008

柔情痞子 提交于 2019-12-01 05:12:26
I am using SQL Server 2008 and a primary key of a database table I am using is not an IDENTITY column (not sure why). I need to change that. I am in SQL Server Management Studio in design view, under column properties and for some reason I can't change the identity specifications to Yes . Is there something that I am missing.. I am new to SQL Server - any ideas on what I am missing?? Here is the create table CREATE TABLE [dbo].[AR_Transactions]( [Trans_ID] [bigint] NOT NULL, [DateTime] [datetime] NOT NULL, [Cashier_ID] [nvarchar](50) NULL, [CustNum] [nvarchar](12) NOT NULL, [Trans_Type]

DBCC CHECKIDENT RESEED — is new value required?

给你一囗甜甜゛ 提交于 2019-12-01 04:05:28
All the documentation I read about reseeding suggests something along the lines of: SET @maxIdentityValue = (SELECT MAX(id) FROM tablename) run DBCC CHECKIDENT('tablename', RESEED, @maxIdentityValue) And yet it appears to me that a simple DBCC CHECKIDENT('tablename', RESEED) is all that's needed, and it will automatically determine the correct identity value from the table without supplying a max value. Is there a reason (performance or otherwise) that extracting the value using MAX first is preferred? Piggyback question: the reason I need to reseed is because I'm using replication and

Auto increment a non-primary key field in Ruby on Rails

∥☆過路亽.° 提交于 2019-12-01 03:55:21
In a RoR migration, how do I auto increment a non-primary-key field? I'd like to do this in the db definition, and not in the model. user386660 You need to execute an SQL statement. statement = "ALTER TABLE `users` CHANGE `id` `id` SMALLINT( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT" ActiveRecord::Base.connection.execute(statement) you can entry manually in your migration Note this is just an example. The final SQL statement syntax depends on the database. 来源: https://stackoverflow.com/questions/3220473/auto-increment-a-non-primary-key-field-in-ruby-on-rails

Reference value of serial column in another column during same INSERT

核能气质少年 提交于 2019-12-01 03:06:23
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). You could use a subquery or a writable CTE to retrieve the value from the sequence once and use it repeatedly : WITH i AS ( SELECT nextval('foo_id_seq') AS id )

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

℡╲_俬逩灬. 提交于 2019-12-01 02:51: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? 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 thing to be aware of is that it is the absolute line number within the file. You can't start numbering on line

How do I add auto_increment to a column in SQL Server 2008

為{幸葍}努か 提交于 2019-12-01 02:22:08
问题 I am using SQL Server 2008 and a primary key of a database table I am using is not an IDENTITY column (not sure why). I need to change that. I am in SQL Server Management Studio in design view, under column properties and for some reason I can't change the identity specifications to Yes . Is there something that I am missing.. I am new to SQL Server - any ideas on what I am missing?? Here is the create table CREATE TABLE [dbo].[AR_Transactions]( [Trans_ID] [bigint] NOT NULL, [DateTime]

DBCC CHECKIDENT RESEED — is new value required?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 01:40:29
问题 All the documentation I read about reseeding suggests something along the lines of: SET @maxIdentityValue = (SELECT MAX(id) FROM tablename) run DBCC CHECKIDENT('tablename', RESEED, @maxIdentityValue) And yet it appears to me that a simple DBCC CHECKIDENT('tablename', RESEED) is all that's needed, and it will automatically determine the correct identity value from the table without supplying a max value. Is there a reason (performance or otherwise) that extracting the value using MAX first is