---
title: "Usage of $ROWGUID and $IDENTITY in SQL Server"  
description: "$ROWGUID  The point of setting the ROWGUIDCOL property is to enable you to use $ROWGUID instead of the column name in a SELECT list. That means we can"  
author: "AVADHESH PATEL"  
published: 2012-09-06  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/358/usage-of-rowguid-and-identity-in-sql-server  
category: "database"  
tags: ["database"]  
reading_time: 2 minutes  

---

# Usage of $ROWGUID and $IDENTITY in SQL Server

The point of setting the ROWGUIDCOL [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) is to enable you to use $ROWGUID instead of the [column name](https://www.mindstick.com/forum/369/how-can-i-add-a-column-name-to-my-grid) in a [SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) list. That means we can use $ROWGUID for [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) ROWGUIDCOL from [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) if ROWGUIDCOL is used.\

##### Demonstration

```
--Create TableCREATE TABLE MYTABLE([ID] UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID(),[NAME] VARCHAR(MAX))-- UNIQUEIDENTIFIER DataType support 16 bit binary value, combination of 0-9 and A-F-- PRIMARY KEY is used for uniquely identify of column values-- DEFAULT is used for auto generated default string-- NEWID() function is used for generated non sequential(randomly) id--Insert RecordINSERT INTO MYTABLE ([NAME]) VALUES ('A')INSERT INTO MYTABLE ([NAME]) VALUES ('B')INSERT INTO MYTABLE ([NAME]) VALUES ('C')INSERT INTO MYTABLE ([NAME]) VALUES ('D') DROP TABLE MYTABLE--Fatch record of UNIQUEIDENTIFIERSELECT ID FROM MYTABLE
```

##### Screen Shot

![Usage of $ROWGUID and $IDENTITY in SQL Server](https://www.mindstick.com/blogs/67ee80a2-7fb7-4b2a-8d7c-b3c5d274edd5/images/ec630b6f-b9c4-4b1d-a01f-703c1c51bac5.jpg)

Here we see, if we want to Fetch UNIQUEIDENTIFIER column record than we have know about column name. if we want to access UNIQUEIDENTIFIER column record without using column name, than use ROWGUIDCOL and $ROWGUID.

```
CREATE TABLE MYTABLE_2([ID] UNIQUEIDENTIFIER ROWGUIDCOL PRIMARY KEY DEFAULT NEWSEQUENTIALID(),[NAME] VARCHAR(MAX))-- UNIQUEIDENTIFIER DataType support 16 bit binary value, combination of 0-9 and A-F-- ROWGUIDCOL property is to enable you to use $ROWGUID instead of the column name in a SELECT list-- PRIMARY KEY is used for uniquely identify of column values-- DEFAULT is used for auto generated default string-- NEWSEQUENTIALID() function is used for generated sequential id--Insert RecordINSERT INTO MYTABLE_2 ([NAME]) VALUES ('A')INSERT INTO MYTABLE_2 ([NAME]) VALUES ('B')INSERT INTO MYTABLE_2 ([NAME]) VALUES ('C')INSERT INTO MYTABLE_2 ([NAME]) VALUES ('D')DROP TABLE MYTABLE--Fatch record of UNIQUEIDENTIFIERSELECT $ROWGUID FROM MYTABLE_2
```

##### Screen Shot

![Usage of $ROWGUID and $IDENTITY in SQL Server](https://www.mindstick.com/blogs/67ee80a2-7fb7-4b2a-8d7c-b3c5d274edd5/images/4dbedd4d-2c4c-4ef5-aa73-e46f2498e298.jpg)

##### $IDENTITY

If we don't know the [IDENTITY column](https://www.mindstick.com/forum/103/how-to-insert-data-in-identity-column) name but wanted to display its column [values](https://www.mindstick.com/forum/327/sum-textbox-values) or Without mentioning the IDENTITY column name how to list all the IDENTITY values in a table.

##### Syntax

```
--Syntax

SELECT $IDENTITY FROM <TABLE NAME>
```

##### Example

```
-- Create TableCREATE TABLE IDENTITY_DEMO([ID] INT IDENTITY(1,1) PRIMARY KEY,[NAME] VARCHAR(20))-- Insert ValuesINSERT INTO IDENTITY_DEMO([NAME])SELECT 'A'UNION ALLSELECT 'B'UNION ALL SELECT 'C' --Fetch Identity Column Record

SELECT $IDENTITY FROM IDENTITY_DEMO
```

##### Screen Shot

![Usage of $ROWGUID and $IDENTITY in SQL Server](https://www.mindstick.com/blogs/67ee80a2-7fb7-4b2a-8d7c-b3c5d274edd5/images/610ab48f-5b62-4340-9eae-782ff0871fac.jpg)

---

Original Source: https://www.mindstick.com/blog/358/usage-of-rowguid-and-identity-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
