Questions tagged [identity-column]

An Identity column is a column in a database table that is made up of values managed by the server and cannot be modified, to be used as a primary key for the table. It is usually an auto-incrementing number.

Several Database products provide means to guarantee unique sequences of numeric values. Manually coding values for a primary key can cause problems.

Common database support: - Oracle: SEQUENCE (stand-alone number generator) and IDENTITY column clause that uses a system-generated SEQUENCE - mySQL: AUTO_INCREMENT column clause - Microsoft SQL Server, IBM DB2: SEQUENCE (stand-alone number generator)

See also for questions not related specifically to a primary key.

368 questions
3
votes
2 answers

C# How to Synch Data Between Database Instances Over the Internet

We have an application that requires our customers to have a SQL server instance on site. At their request, the application needs to synchronize the data in their database with a copy in our datacenter. We're using .Net 3.5 SP1. We need to…
bopapa_1979
  • 8,949
  • 10
  • 51
  • 76
3
votes
2 answers

@@IDENTITY and trigger issue

I'm having the well known problem with a trigger and @@IDENTITY. I created a new Auditing table and a trigger to insert auditing rows on it. We use a software that is using @@IDENTITY and this is causing a conflict with the Id generated when the…
ilabrada
  • 45
  • 4
3
votes
3 answers

Will a trigger be able to copy a primary key that's an identity id?

I want to do after I an INSERT in table X to copy that record into another History table immediately. Now the table has the primary key as an Identity column, so the record won't have an primary key id until it is actually inserted. My question is…
dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
3
votes
5 answers

Is there a smart way to append a number to an PK identity column in a Relational database w/o total catastrophe?

It's far from the ideal situation, but I need to fix a database by appending the number "1" to the PK Identiy column which has FK relations to four other tables. I'm basically making a four digit number a five digit number. I need to maintain the…
3
votes
4 answers

Reinserting rows with identity columns

I'm implementing a queue in SQL Server (2008 R2) containing jobs that are to be performed. Upon completion, the job is moved to a history table, setting a flag to success or failure. The items in the queue table has an identity column as a primary…
Christian Rygg
  • 671
  • 12
  • 26
3
votes
2 answers

SQL Server - how to ensure identity fields increment correctly even in case of rollback

In SQL Server, if a transaction involving the inserting of a new row gets rolled back, a number is skipped in the identity field. For example, if the highest ID in the Foos table is 99, then we try to insert a new Foo record but roll back, then ID…
David
  • 15,750
  • 22
  • 90
  • 150
3
votes
4 answers

How to get dataTables "header name"

DataTable Image -> When i am trying to get header name like this.. then i got only first column name which is NAME... But i need to get all headers name. How to get all Header Name ? this.api().columns().every( function ($i) { var column = this; …
3
votes
2 answers

SQL: Will setting IDENTITY_INSERT ON disable updating the table's identity table?

I'm currently working on a data migration project and for performance-related issues, I want to predefine a set of identities rather than letting the tables generate them. I found it's not easy to add the identity property to a column, so I want to…
thomaux
  • 19,133
  • 10
  • 76
  • 103
3
votes
3 answers

Entity Framework Core attempting to update column marked as Identity in model

I have a database table where one of the columns is an IDENTITY column (not the primary key which is set manually). My EF Core model looks like this: public class Model { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int…
SBFrancies
  • 3,987
  • 2
  • 14
  • 37
3
votes
2 answers

Circular IDENTITY numbers in column

Is it possible to force IDENTITY column to recalculate its seed property , when it reach maximum value for defined data type, to fill gaps in ID's. Let say like this way, I have a column of TINYINT data type which can hold up values to maximum of…
veljasije
  • 6,722
  • 12
  • 48
  • 79
3
votes
3 answers

Compound IDENTITY column in SQL SERVER 2008

An Orders table has a CustomerId column and an OrderId column. For certain reasons it's important that an order's id is no longer than 2-bytes. There will be several million orders in total, which makes 2-bytes not enough for a global order id. A…
Asaf R
  • 6,880
  • 9
  • 47
  • 69
3
votes
1 answer

How to retrieve last autoincremented value in MS-Access like @@Identity in Sql Server

I want to retrieve identity column value in ms access from an autoincremented column. Basically i m running a transaction in which i have to write two insert queries. 2nd query will be containing autoincremented value that was generated from query…
Shantanu Gupta
  • 20,688
  • 54
  • 182
  • 286
3
votes
2 answers

IDENTITY_INSERT is set to OFF?

Here is my script of my db , CREATE TABLE [dbo].[MyTable]( [ID] [int] IDENTITY(1,1) NOT NULL, [Code] [nvarchar](25) NULL, [Name] [nvarchar](25) NULL, [dob] [date] NULL , CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX…
zey
  • 5,939
  • 14
  • 56
  • 110
3
votes
2 answers

Excel - Tell me the column header that had the highest number for each row

| Name | Blues | Greens | Yellows | Reds | Winner | | Smith | 35 | 42 | 52 | 17 | | I want to know the column header that has the largest number for each row and insert its name in the 'Winner' column. How would this be done
Walrus
  • 19,801
  • 35
  • 121
  • 199
3
votes
7 answers

Usage of Table with single column (Identity)?

Whats the purpose of having single column table (identity column)? Is there a good use-case available? Is it really a good practice?
RameshVel
  • 64,778
  • 30
  • 169
  • 213