sql server 2012 - How to get the value for the primary key, which is filled by a default sequence in ms sql? -


for identity

create table [sites] (   [siteid] bigint  identity(1,1) not null,    [name] nvarchar(50)  not null) alter table sites add constraint pk_sites primary key  ([siteid]) 

i

insert dbo.sites(name) values('test'); select @@identity; 

and siteid value.

create table [sites] (   [siteid] bigint  not null default (next value [seqmain]),    [name] nvarchar(50)  not null) alter table sites add constraint pk_sites primary key  ([siteid]) 

how siteid value if filled default sequence?

you can utilize output clause.
enables output values delete, insert, update or merge statement.

you use this:

insert dbo.sites(name) output inserted.siteid values('test') 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -