Pseudocolumns are indirect references to specific columns in a table. For example, the pseudocolumn $IDENTITY will return the value of the identity field within a given table. For example:
CREATE TABLE #test (i1 int IDENTITY(1,1), d1 varchar(10))
INSERT INTO #test (d1) VALUES ('Row 1')
SELECT $identity FROM #test AS t
The select statement returns a recordset showing column i1 by name, and all of its values.
When selecting against a table that does not have the specified pseudocolumn, the query returns the following error (for $rowguid):
SELECT $rowguid FROM #test AS t
---------
Msg 207, Level 16, State 1, Line 1
Invalid column name '$rowguid'.
Simply adding a uniqueidentifier to the table will not remove this error. Instead, you need to add a column with the ROWGUIDCOL property:
ALTER TABLE #test ADD guidcol uniqueidentifier CONSTRAINT Guid_Default DEFAULT NEWID() ROWGUIDCOL
Selecting $ROWGUID at this point will return the values in the guidcol column.
As far as I know, $IDENTITY and $ROWGUID are the only defined pseudocolumns in SQL Server. The $PARTITION value may or may not also be considered a pseudocolumn, but it works on table partitions instead. Since partitions are not columns, I do not consider it to be a pseudocolumn.
commented on Nov 21 2011 1:02PM