auto-increment

Writing a simple incrementing counter in rails

For every Card, I would like to attach a special number to them that increments by one. I assume I can do this all in the controller. def create @card = Card.new(params[:card]) @card.SpecNum = @card.SpecNum ++ ... end Or. I can be blatantly retarded. And maybe the best bet is to add an auto-incremement table to mysql. The problem i...

What is the corrrect way to increment a field making up part of a composit key

I have a bunch of tables whose primary key is made up of the foreign keys of other tables (Composite key). Therefore the attributes (as a very cut down version) might look like this, please note that I am only showing the attributes that make up the key - there would be and are other attributes that are stored alongside the composite ke...

Auto increment over multiple identity columns in MS SQL 2005 or 2008

Hi, I want to have two different tables in MS SQL, for example users and groups, both with identity column. It is possible to create auto increment over two identity columns? I want to have third table with common informations to these two tables and I want to identify unique record. In Oracle is SEQUENCE. It is possible to do it? Tha...

create a cyclic auto increment column in mysql

I have a table that's used to store some temporary bookkeeping stuff. It needs a unique id for each row, so I used an autoincremented column. However, after a while the column reaches it's max value and then I cannot enter new rows into the table. The table is rather small, only ~100 rows at a time since I keep inserting and deleting ro...

SQL insert field, with value of other auto increment field + value

Hi. It might sound complicated, but it's not. I have a table called "orders", with fields: id INT(11) auto_increment, realid INT(14) Now, I want at every insert into this table, do something like: INSERT INTO orders VALUES (null, id+1000); However I'll be doing it on shop which is currently online, and I want to change everything ...

Read Build Number and increment it using a Custom XML File in TFS 2008 using Team Build and msbuild tasks

Hi all, I am trying to accomplish nightly builds and in that i need to automatically increment build number. We have a custom xml file which is already being used by installer and update installer to properly update target system. Before this Nightly Builds, we used to update this file manually and versions of the assembly were manually...

How to read existing assembly version from AssemblInfo.cs files, increment and update the new version using Team Build via TFS 2008?

Hi all, I need to implement auto-increment for each nightly builds. For this, i need to read existing version, increment only the build number and save the incremented build number to assemblyinfo.cs files as well as some custom xml files having the following syntax. <?xml version="1.0" encoding="utf-8"?> <MyProduct> <Version>v.3.0...

mysql manual increment ids?

I have a table with items in it (id, name, etc) and I want some kind of database scheme to be able to have multiple copies of the item while still being able to increment the ids. There will be a field called startdate or date_from_which_this_entry_should_be_used. I've thought of two ways of implementing this: Have a table with only i...

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

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. ...

MySQL auto_increment

I have this table CREATE TABLE `zipcodes2` ( `ID` int(11) NOT NULL auto_increment, `zipcode` int(6) NOT NULL default '0', `State` char(3) NOT NULL default '', `zip_name` varchar(255) NOT NULL default '', `CityAliasName` varchar(255) NOT NULL default '', `latitude` float(26,7) NOT NULL default '0.0000000', `longitude` floa...

Hibernate Auto Increment

I am using hibernate's "increment" generator to generate my auto increment Id's. This was working fine until I had to add another application which also uses the "increment" generator to generate new id's. I realised there is a catch with the increment generator: "generates identifiers of type long, short or int that are unique only wh...

SQL Server Unique Identitifier vs Integer

Hi all, I've been learning ASP.net, and been using the membership system. When it auto generated the tables, I was quite suprised to see it uses a field type called 'uniqueIdentifier' as a primary key, when for many years I have been using an integer field set to be an identity that auto increments. What is the difference (if any at a...

MySQL - how to use VARCHAR as AUTO INCREMENT Primary Key

I am using a VARCHAR as my primary key. I want to auto increment it (base 62, lower/upper case, numbers), However, the below code fails (for obvious reasons): CREATE TABLE IF NOT EXISTS `campaign` ( `account_id` BIGINT(20) NOT NULL, `type` SMALLINT(5) NOT NULL, `id` VARCHAR(16) NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE=MyISAM ...

How to get the id of the added row in Oracle

Hello, I need to translate a script from tsql to plsql, something like: DECLARE @temp_id int INSERT INTO Table (col1, col2) VALUES (1, 2) SET @temp_id = @@identity but, I am having trouble to find something similar to global variable @@identity Oracle expert anyone? ...

How to add 'auto_increment' to another column besides 'id' in rails table defination?

If I need to add 'auto_increment' to a new column called 'another_id' in a table, how can I make it? Is there an option like: create_table :posts do |t| t.integer :another_id, :auto_increment => true # Is there a option like this? ... t.timestamps end In development env I use sqlite3, and mysql in production env; ...

GUID in databases other than SQL Server

Question: I'm planning the database for one of my programs at the moment. I intend to use ASP.NET MVC for the user backend, the database being on Linux and/or on Windows. Now, even if I would only make it for windows, I had to take into account, that different customers use different database systems. Now, I figured I use nHibernate, t...

How to insert new row to database with AUTO_INCREMENT column without specifying column names ?

I have a table with the following columns: id - INT UNSIGNED AUTO_INCREMENT name - VARCHAR(20) group - VARCHAR(20) I know that I can add a row like this: INSERT INTO table_name (name, group) VALUES ('my name', 'my group') I wonder if there is a way to add a row without specifying the column names, like when there is no AUTO_INCREM...

How to use an auto incremented primary key as a foreign key as well?

Hello This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; CREATE TABLE `child` ( `parent_id` int(11) DEFAULT NULL, `related_ids` int(11) DEFAULT NULL, KEY `parent_id` (`parent_i...

How to scale out by evolving from database partitions to sharding?

Say I have a MySQL table: CREATE TABLE tweets ( tweet_id INT NOT NULL AUTO_INCREMENT, author_id INT NOT NULL, text CHAR(140) NOT NULL, PRIMARY KEY (tweet_id) ) PARTITION BY HASH(tweet_id) PARTITIONS 12; All is good. The table lives on a single server - Server1. But eventually I may want to scale out. So I'd want to shard the table and...

Why are numbers being skipped in my auto-increment primary key?

Using MySQL 5.1.37 This isn't really a critical issue, one of our biz-dev people just asked about it and I didn't have a good answer. In our users table we have an auto-increment primary key. From time to time, it skips numbers and seems to be doing so at an increasing rate. My original thought was that when two concurrent signups oc...