identity

Best way to get PK Guid of inserted row

Hi all, I've read this question about getting the identity of an inserted row. My question is sort of related. Is there a way to get the guid for an inserted row? The table I am working with has a guid as the primary key (defaulted to newid), and I would like to retrieve that guid after inserting the row. Is there anything like @@IDE...

Getting new IDs after a bulk insert in SQL Server 2008

I'm inserting a bunch of new rows into a table which is defined as follows: CREATE TABLE [sometable]( [id] [int] IDENTITY(1,1) NOT NULL, [someval] sometype NOT NULL ) using the following insert: insert into sometable select somefield as someval from othertable when I've finished, I'd like to know the IDs of all the newly in...

XSLT : transform only the specified elements

Hi everyone, I am trying to develop an XSLT stylesheet which will transform an xml into another by keeping in view: By default the stylesheet should display nothing for each element (not even the text). If there is an explicit template match for an element, then copy that element, it's attributes and all its sub-elements (and their at...

Sqlite insert into with unique names, getting id

I have a list of strings to insert into a db. They MUST be unique. When i insert i would like their ID (to use as a foreign key in another table) so i use last_insert_rowid. I get 2 problems. If i use replace, their id (INTEGER PRIMARY KEY) updates which breaks my db (entries point to nonexistent IDs) If i use ignore, rowid is not upda...

Making primary key and identity column after data has been loaded.

I have quick question for you SQL gurus. I have existing tables without primary key column and Identity is not set. Now I am trying to modify those tables by making existing integer column as primary key and adding identity values for that column. My question is should I first copy all the records from the table to a temp table before m...

How to insert into a table with just one IDENTITY column

(Came up with this question in the course of trying to answer this other one) Consider the following MS-SQL table, called GroupTable: GroupID ------- 1 2 3 where GroupID is the primary key and is an Identity column. How do you insert a new row into the table (and hence generate a new ID) without using IDENTITY_INSERT ON? N...

Designing an XACML API

Currently, the XACML specification defines a protocol for request / response but leaves it up to interpretation as to how it can be integrated into an enterprise application. I believe that the value of XACML won't be realized unless there is the creation of a new open source project that attempts to develop/standardize around a set of c...

sql server 2005:is it safe to use @@identity?

i have a procedure in which i am inserting record in employee table.nad getting empid by using @@identity ? when this procedure will be called by more than one user at same time,there can be possibility that it returns identity of some other employee inserted at same time.because there is no lock on identity by system? --code --identit...

How do I determine the identity of a Windows machine?

I have a program consisting of a server and a client processes. Both run on Windows systems - Windows 2000 or later versions. The two processes can run on the same machine or on two different machines. How can the client determine if it is run on the same machine as the server? If the server is not running the client can't work anyway a...

Is using MS SQL Identity good practice?

Is using MS SQL Identity good practice in enterprise applications? Isn't it make difficulties in creating business logic, and migrating database from one to another? ...

How can I fix up this Identity int on my DB table?

Hi folks, A week or so ago some data got imported into a db table. Simple table: Id INT PK NOT NULL IDENTITY Name VARCHAR(20) Now, i noticed today that the first id starts at 0. wtf? asking the kid, he was reseeding it during his testing. So the first entry was a zero. Was an accident. Anyways, I'm not sure how to best update the val...

Handling identity columns in an "Insert Into TABLE Values()" statement?

In SQL Server 2000 or above is there anyway to handle an auto generated primary key (identity) column when using a statement like the following? Insert Into TableName Values(?, ?, ?) My goal is to NOT use the column names at all. ...

DDD, value objects and ORM

Value objects got no identity. ORM needs identity to update database. How to trick ORM? (marking Id for value object as internal won't work, cause ORM lives in different assembly and moving it to the same assembly is not acceptable). Thanks in advance. ...

How do I return a new IDENTITY column value from an SQLServer SELECT statement?

I'm inserting into an SQLServer table with an autoincrementing key field. (I believe this is called an IDENTITY column in SQLServer.) In Oracle, I can use the RETURNING keyword to give my INSERT statement a results set like a SELECT query that will return the generated value: INSERT INTO table (foreign_key1, value) VALUES (9, 'text') ...

Increase value of an identity column in SQL Server without dropping and recreating the table

In a table, I have an ID column, that is an Identity int. How can I make it so that the next row inserted will get identity 10000 (I believe this is called the identity seed) - without dropping and recreating the table? I need to do this because of a uniqueness issue with an external service, the app accesses. ...

Increasing Alphanumeric value in user defined function

Hello, I'm trying to code a user defined function under SQL Server 2005 that will increase integer part of alphanumeric value by one. For example, uf_AlphanumericIncrease ('A000299') should return 'A000300'. Here's what I've done so far; ALTER FUNCTION uf_AlphaNumericIncrement ( @ID varchar(10) ) RETURNS VARCHAR(10) AS BEGIN DECL...

Set based insert into two tables with 1 to 0-1 relation.

I have two tables, the first has a primary key that is an identity, the second has a primary key that is not, but that key has a foreign key constraint back to the first table's primary key. If I am inserting one record at a time I can use the Scope_Identity to get the value for the pk just inserted in table 1 that I want to insert into...

How to manipulate WPF GUI based on user roles

I am using C#'s Identity and Principal objects for role based security, and I am at the step of modifing controls shown based on roles the current user has. My question is what the recommended method is for enabling/disabling fields in a WPF window - showing/hiding fields dependent on Identity.IsInRole type calls. Can this be done in X...

SQLSERVER: How to alter an existing table int primary key to become an identity column?

My database has a table with thousands of records. The primary key is an integer. There's a lot of foreign key constraints associated with this column. I want to change this column to become an identity key. What's the best way to do it? I also need to send this update to our clients installations. Bonus points for an answer that work...

Convert a username to a SID string in C#/.NET

There's a question about converting from a SID to an account name; there isn't one for the other way around. How do you convert a username to a SID string, for example, to find out which HKEY_USERS subkey relates to a user of a given name? ...