|
I have a table that normally, upon insert, the auto-key will increment. But, there are some instances when we want to set the ID (as would easily be done with "IDENTITY INSERT" in SQL).
Is there a way to accomplish this with LINQ to SQL?
Thanks,
Started by Timothy Khouri on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Create table MyTable ( Id int primary key identity(1,1), OtherKey int not null, MyData varchar.
If you want.
If you want identity then let the RDBMS handle it.
This, but this just smells of bad design.
|
|
I have below error when i execute the following script;
Could you specify what it is and how it can be resolved?
Insert table(OperationID,OpDescription,FilterID) values (20,'Hierachy Update',1) Server: Msg 544, Level 16, State 1, Line 1 Cannot insert ...
Started by Jaison on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
SET IDENTITY_INSERT Table1 ....
You can turn on identity insert on the table like this so that you can specify your own identity values.
You're inserting values for OperationId that is an identity column.
|
|
I am using a dataset to insert data being converted from an older database. The requirement is to maintain the current Order_ID numbers.
I've tried using:
SET IDENTITY_INSERT orders ON;
This works when I'm in SqlServer Management Studio, I am able to ...
Started by Nathan Koop on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
SET IDENTITY_INSERT orders OFF columns since....
You have the options mixed up:
SET IDENTITY_INSERT orders ON
will turn ON the ability to insert specific values (that you specify) into a table with an IDENTITY column.
|
Ask your Facebook Friends
|
Is it possible to get the @@identity from the SQL insert on a Spring jdbc template call? If so, how?
TIA
Started by javamonkey79 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
This._jdbcTemplate.queryForInt( "select @@identity" );
Decent String INSERT_SQL = "insert into my_test (name) values(?)"; final String name = "Rob"; KeyHolder ps = connection.prepareStatement....
):
// -- call this after the insert query...
|
|
How to retrieve identity ID when inserting a row in the db using linq?
Started by mrblah on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Marc
I'm using the .net Entity Framework and I've came across the similar case .
LINQ to SQL should automatically retrieve the identity of the inserted object, and update the field added IDENTITY.
|
|
Sql server 2005 : i have a column empid in employee table with identity on.if there is some error while inserting data into table .identity is incremented .i want identity to be incremented only if record is inserted .like if i have generated emp id from...
Started by sahil garg on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Edit: Even rolling back the failed transactions will not ... .
If you want your identity numbers to be exactly sequential then you may have to generate them yourself, rather than using the SQL Identity feature.
I don't think this can be done.
|
|
What is the best way to get identity of inserted row?
I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY but don't understand the pros and cons attached to each.
Can someone please explain the differences and when I should be using each?
Started by Oded on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
....
IDENT, see IDENT_CURRENT.
MSDN
@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the value only within the current scope; @@IDENTITY is not limited to a specific scope.
|
|
Am I the only person on this particular planet that is inconvenienced by the lack of Identity Insert , missing in all relevant SSIS Data Flow Transformation objects?
Only the Bulk Insert Task supports Identity Insert, what about elsewhere in SSIS?
Is ...
Started by rasx on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I agree this is a bad INSERT? ....
That gives you identity insert option support.
For what other task do you want IDENTITY source and destination objects.
IDENTITY_INSERT ON/OFF and wrap it all in a transaction.
|
|
I'm trying to do this query
INSERT INTO dbo.tbl_A_archive SELECT * FROM SERVER0031.DB.dbo.tbl_A
but am getting the following error message even after i do
set identity_insert dbo.tbl_A_archive on An explicit value for the identity column in table 'dbo...
Started by jeff on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Allow and the disallow identity inserts for the table with the following statement
SET IDENTITY_INSERT tbl_A_archive ON --Your inserts here SET IDENTITY_INSERT tbl_A_archive OFF
Finally, if you need and....
|
|
Hi,
can anybody please, explain that what does SET IDENTITY INSERT ON AND OFF do.
Thanks, Chris
Answer Snippets (Read the full thread at stackoverflow):
However, if you call SET IDENTITY_INSERT YourTable ON first,....
SET IDENTITY_INSERT ON
Allows explicit values to be inserted into the identity column of a table inserts since it is automatically populated.
|