autoincrement

SqlServer create table with MySql like auto_increment primary key

I want to make a table in SqlServer that will add, on insert, a auto incremented primary key. This should be an autoincremented id similar to MySql auto_increment functionality. (Below) create table foo ( user_id int not null auto_increment, name varchar(50) ) Is there a way of doing this with out creating an insert trigger? ...

Upper limit for autoincrement primary key in SQL Server

What is the upper limit for an autoincrement primary key in SQL Server? What happens when an SQL Server autoincrement primary key reaches its upper limit? ...

Now that I've converted my primary keys to GUIDs, how do I fix the performance?

I'm using TopLink as my ORM and MySQL as the DB. I traded my auto-increment primary keys for GUIDs for one of my tables (alright, not quite: I'm actually using a random 64 bit integer, but that's good enough for my needs). Anyway, now queries, which don't even use the key, are taking much longer. What can I do? ...

Correctly incrementing values using Linq to SQL

I have a MS SQL table that I don't have any control over and I need to write to. This table has a int primary key that isn't automatically incremented. I can't use stored procs and I would like to use Linq to SQL since it makes other processing very easy. My current solution is to read the last value, increment it, try to use it, if I g...

Reset AutoIncrement in SqlServer after Delete

Hello, I've deleted some records from a table in a Sql Server db. Now the Ids go from 101 to 1200. I want to delete the records again, but I want the id's to go back to 102. Is there a way to do this in Sql Server? ...

How to return the value of AUTO INCREMENT column in SQLite with VB6.

I have a table in SQLite: CREATE TABLE "EventType" ( [EventTypeID] INTEGER PRIMARY KEY, [EventTypeName] VARCHAR(50) NOT NULL UNIQUE ); Since EventTypeID is an integer and a primary key, that automatically makes it an auto-incrementing column, and that works fine. I'd like to insert a row into the table and get the newly incremented...

MSSQL Select statement with incremental integer column... not from a table

Hi guys I need, if possible, a t-sql query that, returning the values from an arbitrary table, also returns a incremental integer column with value = 1 for the first row, 2 for the second, and so on. This column does not actually resides in any table, and must be strictly incremental, because the ORDER BY clause could sort the rows of ...

How can I use Integer Auto Increment Field in DBx4 with BlackFish ?

I am trying to use auto incremental fields in dbx4 with a black fish database I have a simple table Structure: CREATE TABLE tblTABname ( ID int AUTOINCREMENT Primary Key, Description varchar(100) NOT NULL ); Before Open I am doing the : qryTAB.FieldByName( ‘ID’).AutoGenerateValue := arAutoInc; cdsTAB.FieldByName( ‘ID’).Au...

SQL - INSERT and catch the id auto-increment value

What is the best way to get the auto-id value in the same SQL with a SELECT? A forum said adding this "; has Return Scope_Identity()" in the end of the SQL works in ASP. Is there a corresponding way in PHP? ...

getting an insert ID from Webkit's HTML5 database storage

Webkit (on iPhone and Safari, at least) supports HTML5's database storage via SQLite. I'm trying to figure out how best to get the insert ID (there's an autoincrement field 'id' in the database) for the following transaction. db.transaction(function(tx) { tx.executeSql("INSERT INTO teams (name) VALUES (?)", [$('#team_name').val()]); ...

How should I go about implementing an "autonumber" field in SQL Server 2005?

I'm aware of IDENTITY fields but I have a feeling that I couldn't use one to solve my problem. Let's say I have multiple clients. Each client has multiple orders. Each client needs to have their orders numbered sequentially, specific to them. Example table structure: Orders: OrderID | ClientID | ClientOrderID | etc... Some example...

SQL server identity column values start at 0 instead of 1

Hi, I've got a strange situation with some tables in my database starting its IDs from 0, even though TABLE CREATE has IDENTITY(1,1). This is so for some tables, but not for others. It has worked until today. I've tried resetting identity column: DBCC CHECKIDENT (SyncSession, reseed, 0); But new records start with 0. I have tried doi...

How can I import data to SQL from CSV or XLS automatically incrementing a string field based on current records in DB?

I need to import data from Excel into a SQL 2000 db. I need to import 6 fields from the worksheet and increment a string field containing an integer padded to 5 characters with leading zeros. This field is not the primary key and the db does not automatically populate this. Also the DB will allow this field to be entered as NULL if this...

Is Access's AutoNumber (Increment) guaranteed to increment?

For a particular table, I have my ID field set to AutoNumber (Increment). If I add 5 rows to this table in quick succession, is each guaranteed to have a larger ID than the last? For instance, does autonumbering ever restart from 1 if some earlier values have been deleted? ...

PostgreSQL Autoincrement

I'm switching from MySQL to PostgreSQL and was wondering how I can do autoincrement values. I saw in the PostgreSQL docs a datatype "serial", but I get syntax errors when using it (in v8.0). ...

SQL Anywhere autoincrement reset

I've got a SQL Anywhere 9 database, and I would like to reset the autoincrement value on one of my columns to a specific number. I guess I need the SQL-Anywhere equivalent of: ALTER TABLE foo AUTO_INCREMENT =100 ...

How can I make a primary key as AUTOINCREMENT

I have table in Database and the primry key is 'ID', Just I want to ask how can I make it AUTOINCREMENT I know that's esay Q, but I dont know how can I do it. thanks ...

How can I make a primary key as AUTOINCREMENT in vb.net 2008?

I have table in a DB and the primary key is the 'TID' column, and I want to make it as AUTOINCREMENT, but I can't, because the "Identity specification" is turned off! See this picture: http://www.rofof.com/img2/6xsbuy6.gif How can I do it? Thanks! ...

How do I return a new IDENTITY column value from an SQLServer SELECT statement?

I'm inserting into an SQLServer table with an autoincrementing key field. (I believe this is called an IDENTITY column in SQLServer.) In Oracle, I can use the RETURNING keyword to give my INSERT statement a results set like a SELECT query that will return the generated value: INSERT INTO table (foreign_key1, value) VALUES (9, 'text') ...

Auto-incrementing attribute with custom logic in SQLAlchemy

Hi everyone! I have a simple "Invoices" class with a "Number" attribute that has to be assigned by the application when the user saves an invoice. There are some constraints: 1) the application is a (thin) client-server one, so whatever assigns the number must look out for collisions 2) Invoices has a "version" attribute too, so I can't...