identity-column

RESEED identity columns on the database

浪尽此生 提交于 2019-11-28 12:11:59
Can I use the DBCC CHECKIDENT(<table_name>, RESEED, value) command to reset an identity column current value to the original one in SQL Server 2008? If yes, is this the correct way of doing this operation without having any drawback? If not, is there an alternate way of doing this? Can I use the DBCC CHECKIDENT command to reset an identity column current value to the original one in SQL Server 2008? Yes. If yes, is this the correct way of doing this operation without having any drawback? This is the one documented way of doing it. Possible drawbacks: you could end up getting duplicate IDENTITY

Get the vector of values from different columns of a matrix

☆樱花仙子☆ 提交于 2019-11-28 10:12:54
I have a matrix 10x4, and I have a vector that has 10 elements. Each element is an column index of that matrix that should be retrieved. Here is the example: > M.mat [,1] [,2] [,3] [,4] [1,] -0.4236174 0.2228897 0.11676857 0.16906735 [2,] -0.4860078 0.9862164 -2.04735716 -0.33708521 [3,] -0.6931023 -0.2255126 -0.58214338 -0.08705187 [4,] 0.4048169 0.8713917 0.38543781 -1.38207954 [5,] 2.4005044 1.2483514 0.66759229 -1.33667156 [6,] -1.2083913 0.2389032 0.29554618 -0.05910570 [7,] 0.8055317 -0.7978780 -0.31873361 0.57248675 [8,] -0.1606493 0.4110878 0.90236993 -0.62311446 [9,] 0.3721249 0

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

限于喜欢 提交于 2019-11-28 08:17:20
问题 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

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

自古美人都是妖i 提交于 2019-11-28 05:16:07
问题 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 ? 回答1: 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

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

泪湿孤枕 提交于 2019-11-27 18:03:53
问题 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

SQL Identity with leading padded zeros

[亡魂溺海] 提交于 2019-11-27 06:52:25
问题 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? 回答1: 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

RESEED identity columns on the database

。_饼干妹妹 提交于 2019-11-27 06:51:02
问题 Can I use the DBCC CHECKIDENT(<table_name>, RESEED, value) command to reset an identity column current value to the original one in SQL Server 2008? If yes, is this the correct way of doing this operation without having any drawback? If not, is there an alternate way of doing this? 回答1: Can I use the DBCC CHECKIDENT command to reset an identity column current value to the original one in SQL Server 2008? Yes. If yes, is this the correct way of doing this operation without having any drawback?

How do you determine what SQL Tables have an identity column programmatically

*爱你&永不变心* 提交于 2019-11-27 06:42:44
I want to create a list of columns in SQL Server 2005 that have identity columns and their corresponding table in T-SQL. Results would be something like: TableName, ColumnName DaveCrawford Another potential way to do this for SQL Server, which has less reliance on the system tables (which are subject to change, version to version) is to use the INFORMATION_SCHEMA views: select COLUMN_NAME, TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where COLUMNPROPERTY(object_id(TABLE_SCHEMA+'.'+TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1 order by TABLE_NAME sys.columns.is_identity = 1 e.g., select o.name, c

BULK INSERT with identity (auto-increment) column

陌路散爱 提交于 2019-11-27 03:48:10
I am trying to add bulk data in database from CSV file. Employee table has a column ID (PK) auto-incremented. CREATE TABLE [dbo].[Employee]( [id] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](50) NULL, [Address] [varchar](50) NULL ) ON [PRIMARY] I am using this query: BULK INSERT Employee FROM 'path\tempFile.csv ' WITH (FIRSTROW = 2,KEEPIDENTITY,FIELDTERMINATOR = ',' , ROWTERMINATOR = '\n'); .CSV File - Name,Address name1,addr test 1 name2,addr test 2 but it results in this error message: Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2

Get the vector of values from different columns of a matrix

妖精的绣舞 提交于 2019-11-27 03:28:32
问题 I have a matrix 10x4, and I have a vector that has 10 elements. Each element is an column index of that matrix that should be retrieved. Here is the example: > M.mat [,1] [,2] [,3] [,4] [1,] -0.4236174 0.2228897 0.11676857 0.16906735 [2,] -0.4860078 0.9862164 -2.04735716 -0.33708521 [3,] -0.6931023 -0.2255126 -0.58214338 -0.08705187 [4,] 0.4048169 0.8713917 0.38543781 -1.38207954 [5,] 2.4005044 1.2483514 0.66759229 -1.33667156 [6,] -1.2083913 0.2389032 0.29554618 -0.05910570 [7,] 0.8055317 -0