identity

Id of object before insertion into database (Linq to SQL)

Hi, From what I gather, Linq to SQL doesn't actually execute any database commands (including the opening of database connections) until the SubmitChanges() method is called. If this is the case, I would like to increase the efficiency of a few methods. Is it possible for me to retrieve the ID of an object before inserting it? I'd rath...

How to get identity value after calling exec(@Sql)

I am trying to find the identity value of an inserted record inserted by exec(@Sql), but it seems that exec() excutes in a different scope. /* create table [dbo].[__Test]( [id] [int] IDENTITY(1,1) NOT NULL, [description] [varchar](100) NULL ) ON [PRIMARY] GO */ declare @Sql varchar(512) set @Sql = 'insert into [dbo].[__Test] ([...

Manually implemented Identity column in SQL Server 2005

Hi all, I have a client that absolutely insists that their database should have no Identity columns, and has manually implemented his own incrementer in a stored procedure that creates table rows. It has been written so that the next ID value is determined and then used in an insert statement. Obviously this is vulnerable to a host of p...

whether the 'identity' used in sql server has been used twice inside same table.

whether the 'identity' used in sql server has been used twice inside same table. ex: i need to insert some set of records with the identity column starting from 0,1,2.... and when i insert some another set of records again the identity must start with 0,1,2.. is there is any possiblity to achieve that using the identity seed. ...

Shared Authentication between SAAS/Cloud web application and Desktop application

A simple scenario: Let's say we have a Web Application up in the cloud that let users sign up using OpenID. (I'm open to use Windows Live ID as alternative) They can log in and update some meta data, for example what their favorite color is. If I now want to get this information from a desktop client, how do I do that? I will probably ...

SQL Server Reset Identity Increment for all tables

Basically I need to reset Identity Increment for all tables to its original. Here I tried some code, but it fails. http://pastebin.com/KSyvtK5b actual code from link: USE World00_Character GO -- Create a cursor to loop through the System Ojects and get each table name DECLARE TBL_CURSOR CURSOR -- Declare the SQL Statement to cursor t...

id columns or clustered primary keys/database consistency

If I had a table with the columns: Artist Album Song NumberOfListens ...is it better to put a clustered primary key on Artist, Album, and Song or to have an autoincrementing id column and put a unique constraint on Artist, Album, and Song. How important is database consistency? If half of my tables have clustered primary keys and t...

problems with singleton COM servers and windows services

Hi, I am using Windows XP SP2, VS 2008 SP1 like this: brought up 2 singleton COM servers out of process in c++ one GUI app in c++ The GUI app used to instantiate both singleton COM servers and then two other programs used to load each singleton COM server - one server for the first prog, the other for second prog. All went well mi...

Generate identity from seed table in Fluent NHibernate

I need to generate an identity from a column in a seed table and increment the value in that column. e.g Seed Table: name "analysisid" id 1 Analysis Table: id name description On the analysis mapping I need to ensure that the id is taken from the seed table and on inserting an analysis the analysisid of the seedid is up...

SQL Server 2005 identity incrementing by itself

Hey. I have a table with an identity column that have incremented by 1 for all its records then suddenly last week it started incrementing in a weird way. For example Identity - Date 31891 2010-02-27 09:47:41 39258 2010-02-27 13:13:03 41994 2010-02-27 13:43:56 45119 2010-02-27 14:44:43 45120 2010-02-27 14:51:33 45121 2010-02-27 1...

Auto generate varchar Ticket number via DB...

Hello, I'm looking for suggestion on how to get the DB to auto generate Ticket numbers (preferably via the SQL DB) for a varchar column. I have the following tables in the DB: Activities & Cases and would prefer the format to be "Act000001" or "Cse000001". This would be something similar to the identity column property. Any suggestio...

Python: object identity question?

>>>a=123>>>b=123>>>a is bTrue>>>id(a)==id(b)TrueMy question is, why is id(a) the same as id(b)?. Aren't they two different instances of class int? ...

How do I insert into a unique key into a table?

I want to insert data into a table where I don't know the next unique key that I need. I'm not sure how to format my INSERT query so that the value of the Key field is 1 greater than the maximum value for the key in the table. I know this is a hack, but I'm just running a quick test against a database and need to make sure I always sen...

SQL Server INSERT, Scope_Identity() and physical writing to disc

Hello everyone, I have a stored procedure that does, among other stuff, some inserts in different table inside a loop. See the example below for clearer understanding: INSERT INTO T1 VALUES ('something') SET @MyID = Scope_Identity() ... some stuff go here INSERT INTO T2 VALUES (@MyID, 'something else') ... The rest of the procedure...

HiLo vs Identity?

This is the same question as: http://stackoverflow.com/questions/803872/hilo-or-identity Let's take the database of this site as an example. Lets say that the site has the following tables: Posts. Votes. Comments. What is the best strategy to use for it: Identity - which is more common. OR HiLo - which give best performance. ...

How to control order of assignment for new identity column in SQL Server?

I have a table with CreateDate datetime field default(getdate()) that does not have any identity column. I would like to add identity(1,1) field that would reflect same order of existing records as CreateDate field (order by would give same results). How can I do that ? I guess if I create clustered key on CreateDate field and then add...

Reset AutoNumber(Identity Field) in DataBase

Hi All I Use a Sql Server Compact Edition DataBase File For Store the Data in My Windows Application Software.In this DataBase I have A Table With Identity Field.When I Insert A Record To the Table, identity Code increment Automatically.But When I Delete All Records From Table,And Insert Records Again,Identity Field don't Start From 1. ...

How can I set default seed for all identities within a SQL Server database?

Is there a way to tell SQL server to use specific default seed value for IDENTITY columns - assuming the (to be run) CREATE TABLE statements do not specify one? I don't really care about altering existing data or altering the seed values for specific IDENTITY columns. I want the same seed for all newly created identity columns. Assume I ...

Using OUTPUT/INTO within instead of insert trigger invalidates 'inserted' table

I have a problem using a table with an instead of insert trigger. The table I created contains an identity column. I need to use an instead of insert trigger on this table. I also need to see the value of the newly inserted identity from within my trigger which requires the use of OUTPUT/INTO within the trigger. The problem is then t...

SQL Server identity counterpart problem

Hi there, I'm using SQL Server and I want to use identity constraint in it I know how to use it in following manner create table mytable ( c1 int primary key identity(1,1); ) the above code works fine but what if i want the identity column to have values as EMP001, EMP002,... instead of 1,2.... Thanks in advance, Guru ...