All Questions

Tagged with
Filter by
Sorted by
Tagged with
3
votes
1answer
45 views

Insert multiple rows into a table with only an IDENTITY column [duplicate]

I have a table called dbo.Groups defined like this: CREATE TABLE dbo.Groups ( GroupID int NOT NULL IDENTITY (1,1) PRIMARY KEY ); The table really consists of just the one IDENTITY column. ...
1
vote
2answers
39 views

What can cause what appears to be missing data in a single table [duplicate]

I have a situation where it appears as if I've lost data in a single table. I have a .NET Core API, with a logging middleware. This middleware takes the entire request and response and stores in the ...
4
votes
1answer
156 views

Can SET IDENTITY_INSERT be allowed with less privileges than db_ddladmin?

I've inherited a system where the application is running under sysadmin account. I limited this account to db_datareader + db_datawriter + EXECUTE on all database and set extended events session to ...
0
votes
1answer
39 views

Pentaho Data Integration - Kettle- Update Identity Column in Microsoft SQL Server

For migration purposes I need to migrate existing ID's from my old database to my new table in MS SQL Server. I can truncate my table in MS SQL Server and then adjust my database connection in ...
8
votes
1answer
616 views

What is the idiomatic solution in SQL Server for reserving a block of ids for use in a bulk insert?

I have a table with an identity column and I want to reserve a block of ids which I can use for bulk inserting, whilst allowing inserts to still happen into that table. Note this is part of a bulk ...
0
votes
0answers
47 views

Transactional Replication : Issues with Identity Column in Subscriber

I have an Transactional replication set up form Server A to Server B. I have a table which has an Identity column as a primary key. In my publisher ,for the table tb1,the the identity column,Id1 was ...
0
votes
1answer
51 views

SSMS: Restart the values on a IDENTITY field [duplicate]

I am starting to use SSMS to manage a database and I am having a problem I would appreciate some help with. I have a table that was created with CREATE TABLE [dbo].[Machine]( [Machine_id] [...
2
votes
1answer
94 views

How do you retrieve the identity value of a row inserted from the OUTPUT of an UPDATE statement?

How do you retrieve the identity value for an inserted row when that row is inserted from the OUTPUT of an UPDATE statement? Neither @@IDENTITY nor SCOPE_IDENTITY() appears to be set properly. ...
2
votes
2answers
156 views

Stored Procedure - Reseed Identity

I have a bunch of LU tables that have values added and deleted all the time. Therefore, I figured writing a quick stored procedure would serve me well and then can call the stored procedure on another ...
2
votes
1answer
485 views

Why am I receiving the identity insert error even after explicitly setting IDENTITY_INSERT ON and using a column list? [closed]

My code: SET IDENTITY_INSERT SomeCoolDatabase.BoringOldSchema.TableWithIdentityColumn ON INSERT INTO SomeCoolDatabase.BoringOldSchema.TableWithIdentityColumn SELECT ColumnWithIdentity, ...
2
votes
3answers
737 views

Is “SET IDENTITY_INSERT” required to insert arbitrary GUID into [uniqueidentifier] column?

SQL Server 2016 and 2017, Standard Edition I need to insert raw data (from another table) into a table that has two uniqueidentifier columns. Does this require that I use SET IDENTITY_INSERT Carrier ...
2
votes
0answers
38 views

Windowed IDENTITY column definition? [duplicate]

Is it possible to create a windowed identity column that automatically initializes and increments in SQL Server 2017 or later? I would like the conceptual functionality of SelectedSubsetId below. ...
5
votes
2answers
552 views

Serializable range deadlocks

Help required on an inherited deadlock problem! The code given below appears to have been written some time back, in an attempt to address contention issues around the assigning of new ID values on ...
1
vote
0answers
65 views

Identity column changing on its own?

I have a situation where a client is using software that writes to a SQL table. The program has been running fine with no issues prior to today. Today, they began receiving errors inserting NULL ...
0
votes
1answer
76 views

Populate Identity column with sequential numbers restarting count on change of key field

I am attempting to populate an Identity column with sequential numbers but I want the count to start over when the value of a key field changes. Example data and desired ID column results: Month_ ...
0
votes
1answer
481 views

How to increment identity without add a row and get the skipped value?

I'm trying to preserve value in identity column in manner to be added later. The value should be used in implicit foreign key when there is no constraint. For example: I have this table: Create ...
0
votes
1answer
369 views

How can I insert without changing the identity seed? [duplicate]

I will add the records in table A to table B. The tables are the same. However, table B is an actively transactional table. When doing the operation, the record in the tableB will continue to be added ...
2
votes
1answer
42 views

SQL Server Replication changing a tables ID numbers

I am using a merge replication setup for our ERP system and I encountered this problem: While creating a new entry on a table and with the last ID number given was 25, then new entry got the ID ...
3
votes
1answer
146 views

Clustered Index Maintenance vs. Nonclustered Index Maintenance

There is a plethora of information available detailing why an IDENTITY field should be use as both the primary key and clustered index of a table for most situations; yet I'm having difficulty ...
0
votes
2answers
113 views

SQL Server - Copying a key from one table to another

In a trigger, I have created a table using SELECT * INTO. I have done that in a specific way, in order to create the table without also creating the identity column that exists in it (let's name this ...
2
votes
2answers
2k views

Availability Group, asynchronous mode, manual/forced failover - handling identity overlap

We have a two replica 2017 Standard Availability Group in asynchronous mode. With a failover (manual/forced, since can't do automatic), we have the potential for overlapping/reused identity values if ...
0
votes
1answer
248 views

Restore all IDENTITY seeds (out of sync since database restore)

We have recently done a full restore on a database from a backup (schema & data). When trying to insert new rows we are getting the "Cannot insert duplicate key in object" error message, it is ...
2
votes
2answers
736 views

Custom Sequences with SQL Server

What is the best method to generate a Custom Auto-Generated Sequence with SQL Server? Here is my requirement: My application is hosted on 10 independent servers which are not interconnected. Each ...
2
votes
1answer
26 views

Existing data to new table, how to set up the PK & Identity

I am moving an Access app to SQL Server. I have confirmed the data in the existing PK is unique so I want to copy it into the new PK Identity field. The field is currently set as IDENTITY(1,1). I ...
1
vote
1answer
210 views

identity value way off in a restored database

I have a table with a identity primary key column. Its last value is 5228491220 using IDENT_CURRENT. I make a full backup of the database, restore it on a second server. (We backup and restore daily ...
1
vote
1answer
413 views

SQL GUID or Identity in the Cloud

Follow up from my previous question SQL Server Identity Column in the Cloud: Are there any general guidelines? Should a person use Clustered Index Identity or GUID in the cloud for SQL Server 2016? ...
-2
votes
2answers
391 views

Problems with having SQL Server Identity Column in the Cloud

Our company is utilizing Identity(1,1) clustered primary index in SQL Server 2016 Enterprise, and will eventually deploy into the Cloud (Amazon AWS, Google Cloud). Is there any issues utilizing ...
0
votes
3answers
1k views

Configured identity seed starting value on database level

Is there an option in sql server to configure the default starting value(seed) of an identity column on a database level . I want that by default, every table that created with an identity column ,...
8
votes
3answers
17k views

How to copy migrate data to new tables with identity column, while preserving FK relationship?

I want to migrate data from one database to another. The table schemas are exactly the same: CREATE TABLE Customers( [Id] INT NOT NULL PRIMARY KEY IDENTITY, (some other columns ......) ); ...
2
votes
1answer
576 views

How to replace a single table with Identity Primary Key column from a database backup?

I need to restore a table from a backup. My understanding is the only way to get a single table back into the database is to copy it into a temporary table. Then drop the old table and rename the new ...
5
votes
3answers
992 views

How to reduce identity values to avoid integer overflow?

I have some leaf tables (no FK towards them) with a few hundreds of thousands records that are used to synchronize some external data using Entity Framework ORM. This involves some DELETEs followed by ...
0
votes
1answer
179 views

Search all table, find PrimaryKeys with Id = int/bigint and enable Identity, autoincrement

I have a large list of tables and due to change in middleware platform, the middleware is no longer creating the auto-increment on Add New Record at the app layer, as a result, I need to do this in ...
4
votes
1answer
316 views

Is there a way to catch a dbcc checkident command

A colleague of mine noticed incorrect ids generated for inserted items. Most probable cause: some script issues a command like the following: dbcc checkident('dbo.table', reseed, 1) I have thought ...
4
votes
1answer
2k views

Restoring database backup makes identity column start at 1 again

I created a backup of our database in SSMS 2012, using Tasks -> Backup as a Full Backup, including all data. When I restore this backup on another server (2012 as well), all identity columns are ...
18
votes
6answers
3k views

What can be the downside of always having a single integer column as primary key?

Within one Web application I am working on, all database operations are abstracted using some generic repositories defined over Entity Framework ORM. However, in order to have a simple design for the ...
8
votes
2answers
15k views

Changing identity column from INT to BIGINT

I have a table with an identity column that is also a primary key. Currently, it has 50 million rows, with the highest value of the identity column sitting at 148,921,803. The table has a lot of ...
19
votes
1answer
2k views

Is it safe to rely on the order of an INSERT's OUTPUT clause?

Given this table: CREATE TABLE dbo.Target ( TargetId int identity(1, 1) NOT NULL, Color varchar(20) NOT NULL, Action varchar(10) NOT NULL, -- of course this should be normalized Code int ...
10
votes
1answer
878 views

Changing primary key from IDENTITY to being persisted Computed column using COALESCE

In an attempt to decouple an application from our monolithic database, we've tried to change INT IDENTITY columns of various tables to be a PERSISTED computed column that uses COALESCE. Basically, we ...
8
votes
1answer
538 views

Is $IDENTITY documented and reliable in SQL Server?

I learned that SQL Server can return the value of the (single) identity column of a table using the pseudo-column $IDENTITY: SELECT $IDENTITY FROM Table Is this feature documented and reliable? The ...
5
votes
3answers
1k views

How to change primary key's data type from int to bigint in a huge transactional database under tremendous load?

This is a legacy system, with more than 1 billion records in a table that undergoes 10 million transactions per day. Now the application complains that: Arithmetic overflow error converting ...
2
votes
1answer
2k views

SET IDENTITY_INSERT OFF - Caused Table Lock

I Executed SQL on database that looked like this: SET IDENTITY_INSERT table1 ON GO BEGIN TRANSACTION GO INSERT INTO table1 SELECT ... FROM table2 GO DELETE FROM table2 ... GO COMMIT TRANSACTION GO ...
8
votes
2answers
5k views

Create a “INTO” table with primary key

Maybe for this community my problem is easy, but for me (a simple Java programmer) it's a BIG problem. I have a Big DB with more and more data. So, the external db admin had create a job that show me ...
3
votes
1answer
232 views

Select a table's current identity from another database

How can I get the current identity of a table using OPENQUERY in SQL Server? How to select the current identity on the table from another database?
7
votes
1answer
537 views

Is there a way to see how SQL Server 2012 defines new identities?

On Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64), is there a way to see what mechanism SQL Server uses to calculate the new identity values for tables created by SELECT INTO? SAMPLE DATA -- ...
4
votes
3answers
4k views

Are auto incrementing identities always given in the order of inserts in SQL Server?

If I create a simple table like this: CREATE TABLE SimpleTable ( [Id] INT IDENTITY(1,1) NOT NULL, [Value] VARCHAR(10) NOT NULL, CONSTRAINT [PK_Email] PRIMARY KEY CLUSTERED ( ...
2
votes
2answers
2k views

Does Clustered Index on GUID create more fragmentation than Non Clustered Index?

I have a simple table: CREATE TABLE [dbo].[UserTestGroups]( [UserTestGroupId] [int] IDENTITY(1,1) NOT NULL, [Token] [nvarchar](100) NOT NULL, [TestId] [bigint] NOT NULL, [Group] [...
0
votes
1answer
171 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 ...
2
votes
1answer
875 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', ...
7
votes
1answer
4k 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 ...
12
votes
1answer
1k 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 ...