identity-column

Auto-increment on Azure Table Storage

我只是一个虾纸丫 提交于 2019-11-30 12:01:33
问题 I am currently developing an application for Azure Table Storage. In that application I have table which will have relatively few inserts (a couple of thousand/day) and the primary key of these entities will be used in another table, which will have billions of rows. Therefore I am looking for a way to use an auto-incremented integer, instead of GUID, as primary key in the small table (since it will save lots of storage and scalability of the inserts is not really an issue). There've been

Reset autoincrement in Microsoft SQL Server 2008 R2

佐手、 提交于 2019-11-30 10:56:58
问题 I created a primary key to be autoincrement. I added two rows: ID=1, ID=2 I deleted these two rows. I added a new row, but the new row's ID was: ID=3 How can I reset or restart the autoincrement to 1? 回答1: If you use the DBCC CHECKIDENT command: DBCC CHECKIDENT ("YourTableNameHere", RESEED, 1); But use with CAUTION! - this will just reset the IDENTITY to 1 - so your next inserts will get values 1, then 2, and then 3 --> and you'll have a clash with your pre-existing value of 3 here! IDENTITY

Auto-increment on Azure Table Storage

ⅰ亾dé卋堺 提交于 2019-11-30 02:25:31
I am currently developing an application for Azure Table Storage. In that application I have table which will have relatively few inserts (a couple of thousand/day) and the primary key of these entities will be used in another table, which will have billions of rows. Therefore I am looking for a way to use an auto-incremented integer, instead of GUID, as primary key in the small table (since it will save lots of storage and scalability of the inserts is not really an issue). There've been some discussions on the topic, e.g. on http://social.msdn.microsoft.com/Forums/en/windowsazure/thread

Reset autoincrement in Microsoft SQL Server 2008 R2

谁说胖子不能爱 提交于 2019-11-29 22:55:43
I created a primary key to be autoincrement. I added two rows: ID=1, ID=2 I deleted these two rows. I added a new row, but the new row's ID was: ID=3 How can I reset or restart the autoincrement to 1? If you use the DBCC CHECKIDENT command: DBCC CHECKIDENT ("YourTableNameHere", RESEED, 1); But use with CAUTION! - this will just reset the IDENTITY to 1 - so your next inserts will get values 1, then 2, and then 3 --> and you'll have a clash with your pre-existing value of 3 here! IDENTITY just dishes out numbers in consecutive order - it does NOT in any way make sure there are no conflicts! If

Oracle identity column and insert into select

ε祈祈猫儿з 提交于 2019-11-29 17:46:14
问题 Oracle 12 introduced nice feature (which should have been there long ago btw!) - identity columns. So here's a script: CREATE TABLE test ( a INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, b VARCHAR2(10) ); -- Ok INSERT INTO test (b) VALUES ('x'); -- Ok INSERT INTO test (b) SELECT 'y' FROM dual; -- Fails INSERT INTO test (b) SELECT 'z' FROM dual UNION ALL SELECT 'zz' FROM DUAL; First two inserts run without issues providing values for 'a' of 1 and 2. But the third one fails with ORA-01400:

Exponentially deteriorating performance on inserts in SQL Server Compact 4.0 tables with an Identity column

假装没事ソ 提交于 2019-11-29 14:34:41
EDIT: the issue below has been fixed in the Entity Framework 6. Running the code below takes a disappointing 2 minutes and 10 seconds. Running it a second time takes 6.5 minutes. This question is related to this one Private Sub RunTest() Dim sw As New Stopwatch sw.Restart() Using db As New TestDB db.Configuration.AutoDetectChangesEnabled = False For n = 1 To 100 For m = 1 To 100 db.Tops.Add(New Top) Next Next db.SaveChanges() End Using MsgBox(sw.Elapsed.ToString) End Sub The Entity: Public Class Top Public Sub New() MyBase.New() One =

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

此生再无相见时 提交于 2019-11-29 11:46:44
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 1. how can i do that ? Rubens Farias However, Microsoft Access 2000 or later does support the @@IDENTITY property to retrieve the value of an Autonumber field after an INSERT Source: Retrieving Identity or Autonumber Values EDIT : As noted by @ David-W-Fenton , you'll also need to use Jet 4.0 OLE DB Provider (this is also described into that previous

Clustered indexes on non-identity columns to speed up bulk inserts?

这一生的挚爱 提交于 2019-11-29 06:56:35
My two questions are: Can I use clustered indexes to speed up bulk inserts in big tables? Can I then still efficiently use foreign key relationships if my IDENTITY column is not the clustered index anymore? To elaborate, I have a database with a couple of very big (between 100-1000 mln rows) tables containing company data. Typically there is data about 20-40 companies in such a table, each as their own "chunk" marked by "CompanyIdentifier" (INT). Also, every company has about 20 departments, each with their own "subchunk" marked by "DepartmentIdentifier" (INT). It frequently happens that a

In Entity Framework, getting the value of an identity column after inserting

匆匆过客 提交于 2019-11-29 03:57:02
I'm using EF4. I want to insert a new MyObject into the database. MyObject has two fields: Id: int (Identity) and Name: string As I've seen in documentation Entity Framework is supposed to set MyObject.Id to the value generated by database after the call to SaveChanges() but in my case that doesn't happen. using (var context = new MyEntities()) { var myObject = MyObjects.CreateMyObject(0, "something"); // The first parameter is identity "Id" context.MyObjects.AddObject(myObject); context.SaveChanges(); return myObject.Id; // The returned value is 0 } UPDATE: This happens in one of my entities

SQL Identity with leading padded zeros

家住魔仙堡 提交于 2019-11-28 12:13:29
I have marked a column as Identity in my table create table Identitytest( number int identity(1,001) not null, value varchar(500) ) I need the identity column to be incremented as 001,002,003 , etc. The database shows that it is inserting as 1,2,3 , etc. How can this be done? If you want to display your number column with leading zeros, just pad it in your SELECT statement. It's a number, it will NOT store with leading zeros as an integer. SELECT RIGHT('00000' + CAST([number] AS varchar(5)) , 3) FROM IdentityTest The 3 is the number of characters you want total in the output display. As the