SQL Server 2005 query shortcuts

SQL Server 2005 introduced some nice shortcuts for working with queries and identity or GUID key columns. These functions are specially useful if you want to write generic functions without worrying about the key names.

 

Given a table Article with an identity column the following query will retrieve all data and an extra column __pkey__ containing the primary key, whatever the name is.

Select $identity as __pkey__,*FromArticle

 

Replace $identity with $rowguid if you are using GUID primary keys.

 

Enjoy!

 


One thought on “SQL Server 2005 query shortcuts

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>