Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Trystan
Frequent Visitor

Alternative to Identity columns in Warehouse

Hello,

What is an alternative way to generate an identity column when using a Warehouse?

 

Trystan_0-1693453963958.png

 

Thanks.

 

 

 

1 ACCEPTED SOLUTION
puneetvijwani
Resolver IV
Resolver IV

@Trystan  you can use ROW_NUMBER() to mannually generate them via sql queries and add the data in your table

Ps: If my response helped, kindly select it as the solution. Your kudos are greatly appreciated!

View solution in original post

3 REPLIES 3
mikeburek
Advocate II
Advocate II

Just an interesting note, as of now, you can create temporary tables with an identity column. Not sure when that started.

 

DROP TABLE IF EXISTS #tempTable
CREATE TABLE #tempTable (a INT IDENTITY (1, 1), b int)
INSERT INTO #tempTable (b) VALUES (1)
INSERT INTO #tempTable (b) VALUES (1)
INSERT INTO #tempTable (b) VALUES (1)
INSERT INTO #tempTable (b) VALUES (2), (2), (2), (2)
INSERT INTO #tempTable 
SELECT 3 FROM #tempTable 

SELECT * FROM #tempTable

 

--------------------

 

But, as of now, you cannot use a permanent table in the same query as a temporary table, so you cannot additionally try to insert this temporary table into a permanent table.

 

Does not work:

DROP TABLE IF EXISTS permanentTable
CREATE TABLE permanentTable (a INT, b INT)
INSERT INTO dbo.permanentTable (a, b)
SELECT a, b FROM #tempTable

Error: Msg 15816, Level 16, State 3, Line 17
The query references an object that is not supported in distributed processing mode.

mikeburek
Advocate II
Advocate II

Adding a note from the future:
There is now a full example of this workaround on Microsoft Learn / Documentation:
https://learn.microsoft.com/en-us/fabric/data-warehouse/generate-unique-identifiers

 

puneetvijwani
Resolver IV
Resolver IV

@Trystan  you can use ROW_NUMBER() to mannually generate them via sql queries and add the data in your table

Ps: If my response helped, kindly select it as the solution. Your kudos are greatly appreciated!

Helpful resources

Announcements
September Fabric Update Carousel

Fabric Monthly Update - September 2025

Check out the September 2025 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.