The tag has no usage guidance.

learn more… | top users | synonyms (1)

0
votes
1answer
66 views

Identity column jump in sql server restart

I had many research on identity column jump in sql server restart. I know the reason why this happen as it explained here. I know the solution how to prevent this using either manually perform ...
1
vote
0answers
41 views

Having 2 identities in a table

I need to have some how 2 identity columns in one table. One that is normal identity and another one that will reset yearly. I have done the reset part with the help of DBCC CHECKIDENT ('TestTable', ...
6
votes
1answer
600 views

Why can a SQL Server table not have more than one IDENTITY column?

Why can a SQL Server table not have more than one identity column? CREATE TABLE t(id INT IDENTITY, id2 INT IDENTITY) Msg 2744, Level 16, State 2, Line 5 Multiple identity columns specified for ...
10
votes
1answer
173 views

Where does SQL Server physically store the IDENTITY VALUE for a table?

I'm hoping someone can point me in the right direction on this one. Here's my workings out so far. SELECT * FROM sys.identity_columns is a system view which gives "last_value" but the definition for ...
6
votes
3answers
1k views

What could cause the wrong ID to be inserted?

I have a SQL Server 2008 server (build 10.0.5500). Earlier this week I ran this on a table that already had data in it: delete from dbo.table go dbcc checkident('dbo.table',reseed,0) When the ...
0
votes
0answers
29 views

NEXT VALUE FOR SEQUENCE inside a CASE Statement

I want to use a new SEQUENCE each year (See here: 'Id' with the format: YYYYNNNNNN with the NNNNNN part restarting each year ) However you can not use NEXT VALUE FOR inside a CASE statement. ...
17
votes
6answers
356 views

Can I rely on reading SQL Server Identity values in order?

TL;DR: The question below boils down to: When inserting a row, is there a window of opportunity between the generation of a new Identity value and the locking of the corresponding row key in the ...
1
vote
1answer
118 views

Identity seed increased when using IDENTITY_INSERT

Running this snippet on SQL Server 2008 produces different result than on SQL Server 2014. I need them to produce the same result. My scenario is that I am writing unit tests (using tsqlt) and this ...
6
votes
1answer
1k views

Getting Identity values to use as FK in an INSTEAD OF trigger

I have a series of updateable views we are exposing to end users as the interface for a back end process. One of these views references two tables and requires an INSTEAD OF trigger for UPDATE and ...
3
votes
1answer
45 views

Identity management in Transaction replication with updatable subscription

I have migrated my publisher DB to new server yesterday. For migration what I did was removed subscriptions and publication completely backed up DB on which publication was configured restored DB ...
4
votes
1answer
94 views

SQL 2012 insert data into a table from another table and custom columns

I'm trying to insert data from one table into another table and I also have 4 columns that are not in the source table but need to be populated in the target table. Here is the Insert statement SET ...
0
votes
1answer
36 views

DBCC CHECKIDENT behaving inconsistently

I have a script that sometimes needs to be run on a fresh database that's just had all the tables created and sometimes needs to be run on an existing database. I have a script to wipe out the tables ...
5
votes
3answers
351 views

Add autoincrement to existing PK

I created a table in a DB that already exists in another DB. It was initially populated with the old DB data. The table's PK had to receive the values that already exist on those records, so it ...
0
votes
1answer
49 views

Select Into removes IDENTITY property from target table

I am doing an exercise which removes the IDENTITY property from the target table when using a select into statement. source table name: Sales.Orders column name: orderid column property: int ...
5
votes
2answers
392 views

Reseed identity column in all empty tables

I need to write a query that resets the identity on all tables that have an identity column and are empty.
2
votes
2answers
59 views

Finding and listing all columns in a SQL Server database with identity [duplicate]

I wanted to RESEED all the identity columns in that database, so I need to create a script so I can find out which column in which table has the identity property.
4
votes
1answer
3k views

How to set identity_insert to on in SQL Server

I get the command set identity_insert table_name on;, but for some reason it is not actually changing the attribute. I've done it with the account that I created the table with, and I've also created ...
-2
votes
2answers
88 views

Change IDENTITY_INSERT to ON in SQL server [duplicate]

How can I insert an ID into an identity column in SQL Server? I'll make a special item into my table and I will quickly detect that item by the ID. So because all other ID's are bigger or equal to ...
4
votes
6answers
5k views

using IDENTITY column with increment -1

I need to run a sql server logging db with 2 main tables in 2 seperate datacentres writing to both at the same time. I had the idea of restoring the db to the new datacentre and then reseeding the ...
4
votes
2answers
2k views

How to remove identity specification for multiple tables

I am having total 109 table in Database and now i am migrating to Amazon server with identity insert and now i want to remove auto increment column specification for all tables. How set auto increment ...
1
vote
1answer
335 views

MERGE with IDENTITY_INSERT ON does not work if Identity is not the primary key

I frequently use MERGE statements and am quite familiar with it. Now I ran into a situation where some tables have IDENTITY columns that are not the primary key. In this situation the script failed ...
1
vote
0answers
249 views

Sudden PRIMARY KEY violation on IDENTITY column

I have a log table with an ID identity column. Everything works fine for years; then, yesterday, I see the following error in the logs: The statement has been terminated. Violation of PRIMARY ...
0
votes
0answers
19 views

MySQL Trigger at Insertion with nested CAST

So I'm using MySQL 5.5 and trying to insert a VARCHAR as ID (since my teacher requested so), I am trying that each time there is an insertion of a new USER, a trigger automatically assigns an ID to ...
52
votes
10answers
8k views

Why do people recommend not using the name “Id” for an identity column?

I was taught not to use the name Id for the identity column of my tables, but lately I've just been using it anyways because it's simple, short, and very descriptive about what the data actually is. ...
0
votes
1answer
339 views

Using Identity Insert on a linked server

We have a database hosted in Microsoft Azure and using this database connection details I have created a linked server object in SSMS on our on-premise SQL box and I can insert into it as following ...
1
vote
1answer
42 views

Reseeded Identity not showing in GUI

I am reseeding my Identity Seed with the following T-SQL: USE DATABASENAME; GO DBCC CHECKIDENT ('dbo.DOCUMENT', RESEED, 400000000); GO I am subsequently checking it went through: USE DATABASENAME; ...
0
votes
0answers
25 views

What can be the cause of sudden leaps in identity? How can it be undone? [duplicate]

In one of our clients' (testers') databases the Identity column of a SQL Server Local Db datatable looks thus: So, most of the time the identity increases by one, but sometimes the identity jumps ...
2
votes
4answers
2k views

Merge Replication identity field issues

One of our clients is using our software with merge replication of a database on a SQL Server 2008 R2 machine. There are two production environments in separate geographical locations only one of ...
4
votes
1answer
575 views

Scope_Identity() returns null after inserting first row in table

I have a stored procedure that is used for inserting values in two tables. The tables have a parent-child relationship i.e. the first table has an identity column, and the second table references the ...
9
votes
1answer
607 views

Why is removing the Identity property on a column not supported

I have read that after SQL Server 2000, the ability to "un-identity" an identity column was removed. And that this was "By Design" (not just a missing feature). Here is an example I found on a blog. ...
0
votes
0answers
21 views

Compare 2 tables and display only the columns that do not match [duplicate]

I wanted to compare 2 identical tables and displat only the columns that do not match.. Suppose I have table temp A and table temp B, IF OBJECT_ID('tempdb..#A') IS NOT NULL BEGIN DROP TABLE #A END ...
3
votes
1answer
220 views

Gigantic gaps in IDENTITY column

This question is about strange behavior in SQL Server 2008 R2 SP3 Standard Edition x64. I have read many questions about IDENTITY increments in SQL Server and strange gaps between them. But basically ...
5
votes
4answers
648 views

Primary Key choice on table with unique identifier

I'm reconsidering my choice of Primary Key on a table, and would like some input. Some context: We are building a REST API, where clients access "Assets" identified by a GUID. So, the table for ...
1
vote
1answer
124 views

Identity column value falling behind randomly

We are having a strange intermittent issue where the identity column value falls behind the MAX(ID) for the table. Each customer gets their own table that stores statistics to the tune of ...
0
votes
0answers
146 views

Can I simulate a sequence in pre-2012 SQL Server, with separate identity column, in function style?

A database on SQL Server 2005/2008/R2 is currently using an identity column in a separate table as primary key source. The reason is that the application, with NHibernate as ORM, needs to know the PK ...
5
votes
1answer
564 views

Adding PRIMARY KEY and IDENTITY attributes to SQL Server 2008 tables

An application is using an SQL Server 2008 database that has ID columns, but these columns are not primary keys and have no IDENTITY attribute. What I need to do now is adding the PKs and IDENTITY ...
0
votes
0answers
89 views

How to reset @@IDENTITY value inside a Sybase SP

Is there any way to reset the @@IDENTITY value inside a Sybase SP? I'm writing a SP which involves a transaction, so everytime I do an insert, to check data was correctly inserted, I assign ...
0
votes
1answer
75 views

Set Identity as (11 - 2) in sql table

I have a issue, I want to set the ID column, where the ID should start from 11-2 then it should auto- increment by 1 like 11-3, 11-4. I am using sql-server 2008 R2. Please help
2
votes
0answers
186 views

Identity in a view treated as ordinary int - migrating from SQL Server 2000 to 2012

I'm migrating a very old platform from a SQL Server 2000 backend and MS Access 2003 as its frontend to SQL Server 2012 backend and MS Access 2010 as the frontend. This obviously means a bit of ...
0
votes
1answer
172 views

Mysql Get Column Name after Case Max [closed]

i have this scenario with this query that trasform multiple rows key/values in a columns. SELECT t1.*, t2.*, u.name, u.email, u.username, MAX(CASE WHEN t2.datakey = 'latitude' THEN t2.data END) ...
2
votes
1answer
3k views

Identity value jumps when restarting SQL Server

We just switched from SQL Server 2008 R2 to SQL Server 2012. I am facing a problem with identity columns: Whenever I restart SQL Server, the seed value for each identity column is increased by 1000 ...
1
vote
2answers
1k views

Assigning new auto increment value [duplicate]

I have a table that is created as below. CREATE TABLE [dbo].[Table1]( [ID] [INT] IDENTITY(1,1) NOT NULL, [Title] [VARCHAR](255) NULL, ... Lets say that the latest ID is 100 ( I have 100 ...
0
votes
1answer
37 views

Composite Key for Gizmo Tracking

I'm trying to setup a many to many relationship between an gizmo table and a owner table. A owner can have many gizmos And a gizmo can have many owners When I have a linking table do I set the ...
-1
votes
1answer
483 views

SQL Server: performance of IDENTITY vs INT as primary key

The most important table of my database is about 300,000 records, and growing. More than 20 tables have a FK to it. Its primary key is a number, but for historical reasons is defined as nvarchar(6) ...
0
votes
2answers
861 views

How to create identity field in MySQL without using auto_increment column?

I am trying to create a dynamic system when a user can create different objects and relate them to another objects. I need is to be able to generate an identity column similar to auto_increment but ...
0
votes
1answer
20 views

Separate table creation at runtime or add column

I am planning to keep patient data in a patient table. I will have multiple Clients registered with me, and each client will have multiple doctors. Should I make patient table client wise or a single ...
4
votes
2answers
225 views

removal of GUIDS used for all PK's, FKs & Clustered indexes

Inherited control over a database that has this nasty config. It also has large sections of code generated by NHibernate, including the gneeration of GUIDs before they get to the db so no chance of ...
3
votes
2answers
1k views

How to update ID=null values in table to incremental counter values?

On SQL Server 2012, i've got an intermediate/staging table for merging existing with new data, where I want to insert numeric IDs for newly created rows: ID NaturalID Comment 1 ...
2
votes
1answer
8k views

Using scope_identity() to get ID “during” insertion of row?

I have a column that has an ident_current constraint on it to populate another column, like so: alter table dbo.Employee add constraint dbo_Employee_D1 default ident_current('dbo.Employee') for ...
4
votes
3answers
4k views

Identity column as clustured index bad idea?

Its just been a few months of programming in SQL Server for me so my knowledge is not good in many regards. In an already existing project at work I came across many tables with large composite ...