auto-increment

Sequences with composite primary key

跟風遠走 提交于 2019-12-06 05:05:48
问题 Using PostgreSQL, how do I manage a sequence (auto incremented Integer id) for the following scenario- Table named 'businesses' which has 'id' and some more columns. Table named 'users' which has: a composite primary key, composed of a 'business_id', and an 'id', and have the 'id' reset it's counting for each 'business_id' when I insert now rows. a simple column 'name'. something like having a separate sequence per business. Example When I run the following queries: insert into users

How to add autoincremental field in OpenERP 7?

假如想象 提交于 2019-12-06 03:29:32
问题 I searched and modified the source code of a simple custom module of openerp, I give the code below init .py import sim openerp .py { 'name': 'Student Information Management', 'version': '0.1', 'category': 'Tools', 'description': """This module is for the Student Information Management.""", 'author': 'Mr Praveen Srinivasan', 'website': 'http://praveenlearner.wordpress.com/', 'depends': ['base'], 'data': ['sim_view.xml'], 'demo': [], 'installable': True, 'auto_install': False, 'application':

mySQL Database: Reset AutoIncrement Fields

倾然丶 夕夏残阳落幕 提交于 2019-12-06 03:01:57
while the development of websites we use the database to test & all... which consumes a lot from auto generated (auto increment) attributes series... how to reset everything... Assuming you're deleting the records when you're done testing, a TRUNCATE command will delete all records and reset the autoincrement value. ALTER TABLE _TABLE_ AUTO_INCREMENT=1 Another possibility, avoiding transactions and resetting the autoincrement counter could be to combine the select to get the next available id and the insert itself; INSERT INTO tablename (id, somefield1, somefield2) SELECT max(id)+1, 'test', 5

Autoincrement Primary key in Oracle database

心不动则不痛 提交于 2019-12-06 02:07:54
问题 I would like to achieve an identity or auto-incrementing value in a column ala SQL Server: CREATE TABLE RollingStock ( Id NUMBER IDENTITY(1,1), Name Varchar2(80) NOT NULL ); How can this be done? 回答1: As Orbman says, the standard way to do it is with a sequence. What most people also do is couple this with an insert trigger. So, when a row is inserted without an ID, the trigger fires to fill out the ID for you from the sequence. CREATE SEQUENCE SEQ_ROLLINGSTOCK_ID START WITH 1 INCREMENT BY 1

Adding auto-incremented values to a table with one column

会有一股神秘感。 提交于 2019-12-06 02:01:40
I need to create a table that basically keeps a list of indices only. Therefore I've created a table with just one, auto-incremented column called 'id'. However, I can't seem to implicitly add auto-incremented values to this table. I know that usually when you have such a column in a table (with more than just this column) you can do: INSERT INTO TABLE (col1, col2 ...) VALUES (val1, val2 ...) And if you don't specify the auto-incremented column, it would automatically get a value. However, things like: INSERT INTO TABLE () VALUES () INSERT INTO TABLE INSERT INTO TABLE () etc. all produce an

How to get the auto-increment primary key value in MySQL using Hibernate

余生长醉 提交于 2019-12-05 21:37:00
问题 I'm using Hibernate to access MySQL, and I have a table with an auto-increment primary key. Everytime I insert a row into the table I don't need to specify the primary key. But after I insert a new row, how can I get the relative primary key immediately using hibernate? Or I can just use jdbc to do this? 回答1: When you save the hibernate entity, the id property will be populated for you. So if you have MyThing thing = new MyThing(); ... // save the transient instance. dao.save(thing); // after

hibernate not generate auto increment constraint on mysql table

谁说我不能喝 提交于 2019-12-05 20:55:54
I have been searching through different forums for the problem and had tried different solutions but i am still unable to find any correct answer for my problem. I am using hibernate4 annotations for mapping my entities. everything works fine but only auto increment key is not detected when tables are created using hibernate in mysql. i have following code: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(unique = true, nullable = false) private int responseId; i also have tried @Id @GenericGenerator(name="generator", strategy="increment") @GeneratedValue(generator="generator")

Reset PK auto increment column

醉酒当歌 提交于 2019-12-05 19:56:06
I've been importing thousands of records multiple times in an effort to get the import running perfectly. As a result, now when I do the live import before release, the ID columns for the auto increment column are on around 300,000. Is there any easy way to 'reset' this once I have deleted all the data from these tables? I only want to for SEO reasons, the URL: Forum/1/Post Forum/35/Post Forum/5600/Post Looks a lot nicer and more concise (therefore more clickable in results) than Forum/300124/Post Forum/370321/Post Forum/450111/Post I'd rather not delete the column and reinsert the column as

Why am I unable to find a record by _id in mongodb

心已入冬 提交于 2019-12-05 18:16:12
问题 I am trying to find a record in mongoDB by it's MongoID "_id" field. I have found examples on how to do it, but can not get it to work. Example: $recID = "010101010101011"; //would be a valid mongodb _id $recID = new MongoId((string)$recID); // I have tried it without the (string) cast too $cursor = $this->Collection->findOne(array('_id' => $recID)); print_r($cursor); It outputs: MongoCursor ( ) Nothing inside. I have verified everything else is working by changing the "_id" above to a

What to do if the auto-increment value reaches its limit?

天大地大妈咪最大 提交于 2019-12-05 16:38:59
I am doing a little research for a problem that might occur someday. Lets say you have an InnoDB MySQL table with an id and a name field. the id field has BIGINT(20) and is AUTO_INCREMENT plus its the primary key. What do you do in a case that this table is full which means we have reached the limit on the id and no auto increment number can be generated anymore. Let's assume a table structure like: CREATE TABLE `tbl` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ); and INSERT queries like: INSERT INTO tbl(id) VALUES (NULL); In the real code there are also other columns