Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server materialized with ID column auto Increment

Tags:

sql-server

I want to create a SQL Server table materialized view where I want to add an extra column named ID which is auto increment.

Is that possible?

like image 635
Kernelv5 Avatar asked May 02 '26 21:05

Kernelv5


1 Answers

No, that's not possible. The restrictions on indexed views prevent this.

The ID would not be stable anyway. It would change in unexpected ways when the underlying data changes. The view is not a persistent table. It reflects what the view definition says at all times.

Use something else as the key of the indexed view. Usually, there is a suitable combination of columns from the underlying tables.

like image 142
usr Avatar answered May 04 '26 13:05

usr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!