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

Python - find average for columns with unique matching value in nested list

This is very similar to this question: Finding minimum, maximum and average values for nested lists? The important difference and root of the question being I would like to find min, max, average within a list (nested within a list) for each unique…
d-cubed
  • 1,034
  • 5
  • 30
  • 58
3
votes
1 answer

How do I add the IDENTITY property to existing SQL Azure table?

I have created a couple of tables in SQL Azure and forgot to mark the primary keys as identity columns. There is no data in the tables yet, but the check box marked Is Identity is disabled. How do I make an existing primary key an identity column…
Feckmore
  • 4,322
  • 6
  • 43
  • 51
3
votes
1 answer

How to use InsertOrReplace in BLToolkit.3

I start using BLToolkit and there is a new advantage: InsertOrReplace When I try to use it there is an exception: "InsertOrUpdate method does not support identity field 'Margin.id'" My Model here: [TableName("Margin")] public class Margin …
user1706449
  • 159
  • 1
  • 1
  • 9
3
votes
2 answers

Update a Current table Column to an Identity Column

Possible Duplicate: set identity on the column I have a table let's say Messages with a column name Serno. Serno keeps the serial number for each message. However system is very old and creates this serial number using max(serno) command. Now, I…
M.A
  • 273
  • 2
  • 8
3
votes
2 answers

SQL Server 2012 scope_identity advise

I created a stored procedure in SQL Server 2012 and I have used scope_identity to get identity column's value but in my case I do not know is this correct or not please help CREATE PROCEDURE Add_Translation @english nvarchar(70), @kurdish…
danarj
  • 1,798
  • 7
  • 26
  • 54
3
votes
8 answers

When Would You Choose NOT to Use an Identity/Autonumber Field as Your Primary Key?

I don't believe in a Silver Bullet, but I really like to use sequences or autonumber identity columns as my primary key columns for database tables. They're unique, they index well, and I don't have to worry about null values. On the other hand, in…
Mike Hofer
  • 16,477
  • 11
  • 74
  • 110
2
votes
1 answer

Uniqueidentifier as Identity in SQL Server CE?

In SQL Server CE can I create an identity column with data type uniqueidentifier? If so, how? If not, why not? I have tried creating it with "New Table"from the Server Explorer in VS2010, and the Identity option only gets enabled when the type is…
tycom iplex
  • 131
  • 1
  • 8
2
votes
2 answers

How to increment the Identity column

I am using identity columns as a primary key in my tables. In some situations I need to work with primary keys before inserting a new row. For example, in Oracle I use : select .nextval into from dual and I was sure that no…
Maxim Shevtsov
  • 212
  • 1
  • 3
  • 10
2
votes
1 answer

Turn ON OFF IDENTITY INSERT equivalent in Oracle

I have the following ProductCategory dimension in my DWH design to not lose data : ProductSK ProductID ProductName BI_StartDate BI_EndDate -1 -1 Undefined 99991231 99991231 The ProductSK is an identity column. I am used to use…
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
2
votes
3 answers

Will having a pseudo-incremental number for bug ID be a problem?

Note that when I say "client", I mean businesses or organizations that have signed up for the service. I am creating a bug tracking application. I have decided to go with multi-tenant approach with respect to both the application instance and the…
user529141
2
votes
1 answer

Azure SQL DW - Identity column values

I'm inserting primary/composite keys into an intermediary database table with an identity(1,1) bigint column. In more traditional relationship databases, this column increments by 1 for each new key in the table, creating a surrogate key for the…
Alexus Wong
  • 347
  • 4
  • 9
2
votes
3 answers

What would my SQL statement be to insert "Arnold Schwarzenegger" and "Hasta la vista baby" into these two empty SQL tables?

What would my statement be to insert "Arnold Schwarzenegger" and "Hasta la vista baby" into the following empty SQL tables? The title of this question was originally going to be "How to insert the first records into SQL tables with bidirectional…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
2
votes
3 answers

Is the SQL Server identity function reproducible

I want to add an identity column to a table that does not have an ID column so far using Alter Table Names Add Id_new Int Identity(1, 1) EDIT: My question seemed to have led to some confusion, so I try to clarif: We got a few thousand tables…
aldorado
  • 4,394
  • 10
  • 35
  • 46
2
votes
1 answer

Sql Server - counter column that increments even with transactions rollback

I need to manage an incremental counter (protocol number) for every year of my product life. The value must be unique inside each year, and I need that once the counter has been incremented it cannot be rolled back. If I make a stored proc that…
David
  • 33
  • 1
  • 5
2
votes
2 answers

How can I reset IDENTITY column of my table in SQL Server?

How can I reset my IDENTITY column in my already populated table? I tried something like this, but it's not working WITH TBL AS ( SELECT *, ROW_NUMBER() OVER(ORDER BY profile_id) AS RN FROM Profiles ) UPDATE…
Biswa
  • 343
  • 2
  • 4
  • 14