identity-column

“There can only be one IDENTITY column per table” - Why?

╄→гoц情女王★ 提交于 2020-01-11 05:16:27
问题 "There can only be one IDENTITY column per table" Why is it so? Take a scenario of a vehicle, there exists a chasis number which is unique as well as the registration number which turns out to be unique. To depict this scenario in sql server we need a custom implementation for on of the columns. Conversely, in Oracle you can have as many sequences as you want on a table. Why is there a restriction on the IDENTITY Column, any specific reasons? The scenario of having a vehicle schema is

SQL Arithmetic Overflow for Identity Insert

依然范特西╮ 提交于 2020-01-05 19:06:12
问题 I have an error with arithmetic overflow inserting values into a lookup table with a row-id set as TINYINT datatype. This IS NOT a case where the number of unique records exceeds 255 values. This is a bit more unusual and did not occur during the first tests of this setup. The production version of the code below actually only has 66 unique values, but it is possible that new values could be added (slowly and in very small numbers) over time... 255 available slots should be more than enough

Map a column to be IDENTITY in db

戏子无情 提交于 2020-01-05 16:32:42
问题 Although I have marked my ID column with .Identity() , the generated database schema doesn't have IDENTITY set to true, which gives me problems when I'm adding records. If I manually edit the database schema (in SQL Management Studio) to have the Id column marked IDENTITY , everything works as I want it - I just can't make EF do that by itself. This is my complete mapping: public class EntryConfiguration : EntityConfiguration<Entry> { public EntryConfiguration() { Property(e => e.Id)

Get IDENTITY value in the same T-SQL statement it is created in?

南楼画角 提交于 2020-01-03 17:32:25
问题 I was asked if you could have an insert statement, which had an ID field that was an "identity" column, and if the value that was assigned could also be inserted into another field in the same record, in the same insert statement. Is this possible (SQL Server 2008r2)? Thanks. 回答1: You cannot really do this - because the actual value that will be used for the IDENTITY column really only is fixed and set when the INSERT has completed. You could however use e.g. a trigger CREATE TRIGGER trg

Get IDENTITY value in the same T-SQL statement it is created in?

一个人想着一个人 提交于 2020-01-03 17:31:13
问题 I was asked if you could have an insert statement, which had an ID field that was an "identity" column, and if the value that was assigned could also be inserted into another field in the same record, in the same insert statement. Is this possible (SQL Server 2008r2)? Thanks. 回答1: You cannot really do this - because the actual value that will be used for the IDENTITY column really only is fixed and set when the INSERT has completed. You could however use e.g. a trigger CREATE TRIGGER trg

EF returns 0000-0000-0000-xxx as Guid when I try save a new record or update existing record?

六眼飞鱼酱① 提交于 2019-12-30 11:06:35
问题 I am using EF4 in my C# project. The problem I'm faced with is that, when I try to save a record, I get a Primary Key Violation and the PK value is "0000-0000-0000-xxx". From my guess, EF does not recognize the IsIdentity flag and generate a guid value. In my SQL Server database for my table, I specify a PK(uniqueidentifier>guid) and also set it as the IdentityColumn, thus I would expect this to travel through to my project as such since the guid is generated in SQL Server. Is there a way to

Inserting into Oracle and retrieving the generated sequence ID

混江龙づ霸主 提交于 2019-12-28 03:36:07
问题 I have a handful of raw SQL queries for SQL Server which use SCOPE_IDENTITY to retrieve the generated ID for a specific INSERT immediately after that INSERT occurs all in one execution… INSERT into Batch( BatchName, BatchType, Source, Area ) Values ( @strBatchName, @strType, @strSource, @intArea ); SELECT SCOPE_IDENTITY() BatchID; The question is: What’s the best way to do that for an Oracle database? Can this be done on Oracle through standard SQL or do I have to switch this to use a stored

LINQ Inserts without IDENTITY column

牧云@^-^@ 提交于 2019-12-25 04:38:08
问题 I'm using LINQ, but my database tables do not have an IDENTITY column (although they are using a surrogate Primary Key ID column) Can this work? To get the identity values for a table, there is a stored procedure called GetIDValueForOrangeTable(), which looks at a SystemValues table and increments the ID therein. Is there any way I can get LINQ to get the ID value from this SystemValues table on an insert, rather than the built in IDENTITY? As an aside, I don't think this is a very good idea,

Calculate mean and sd by ID and Day within a column

风格不统一 提交于 2019-12-24 20:25:56
问题 I'm new to R and need to summarize mean and sd of my data in a new table: The raw data look like that: ID Day pH 1 1 7 1 1 7.2 1 1 7.1 2 1 7.3 2 1 7.4 2 1 7.2 3 1 7 3 1 7.1 3 1 7.5 4 1 7.3 4 1 7.2 4 1 7.6 1 2 7 1 2 7.2 1 2 7.1 2 2 7.1 2 2 7.4 2 2 7.2 3 2 7.5 3 2 7.1 3 2 7.5 4 2 7.2 4 2 7.2 4 2 7.3 1 3 7.4 1 3 7.2 1 3 7.1 2 3 7.2 2 3 7.4 2 3 7.2 3 3 7.4 3 3 7.2 3 3 7.5 4 3 7.4 4 3 7.2 4 3 7.7 And the table I want should look like: ID Day pHmean pHsd 1 1 7.1 0.10 2 1 7.3 0.10 3 1 7.2 0.26 4 1 7

SQL CE Compact 3.5 Identity columns for a table

谁说我不能喝 提交于 2019-12-24 00:06:39
问题 Is there a query I can write against an INFORMATION_SCHEMA or against the system tables to determine if a column is an identity column in SQL CE version 3.5? 回答1: Use COLUMNPROPERTY . For ur reference a) COLUMNPROPERTY (Transact-SQL) b) Identity Columns 回答2: Try the following query: ;WITH PK_INFO AS (SELECT CON.TABLE_CATALOG, CON.TABLE_SCHEMA, CON.CONSTRAINT_NAME, USO.COLUMN_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS CON JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE USO ON CON.CONSTRAINT_NAME