sql server - T-SQL Unique Identity Column as Part of Composite Primary Key -



sql server - T-SQL Unique Identity Column as Part of Composite Primary Key -

suppose have table next structure:

create table [log] ( [type] int not null, [stat] nvarchar(20) not null, [id] int identity (1, 1) not null, descr nvarchar(20), primary key ([type], [stat], [id]) )

is possible forcefulness [id] incremented whenever other 2 pk fields have same values, , not independently now? instance:

type stat id descr 5 error 1 test <--- 3 warning 1 test 5 error 2 test <--- 2 error 1 test 1 warning 1 test 5 warning 1 test 5 error 3 test <---

no. purpose of identity (or sequence) generate incremental integer. there may gaps values not reused, , values may reserved not used.

you can utilize look in queries show desired value.

row_number() on (partition type, stat order id) seq

sql sql-server tsql primary-key composite-primary-key

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -