Reputation: 107
When trying to run an insert statement:
ALTER proc [dbo].[sp_register]
@code int output,
@name varchar(50),
@description varchar,
@phone int
as
insert into user (code,name,description,phone)
values (@code,@name,@description,@phone)
set @code = @@IDENTITY
I get the following error:
Msg 544, Level 16, State 1, Procedure sp_register, Line 8
Cannot insert explicit value for identity column in table 'user' when IDENTITY_INSERT is set to OFF.
Upvotes: 1
Views: 7554
Reputation: 103525
You can't insert into the code
column, because it's automatically generated.
Change it to:
insert into user (name,description,phone)
values (@name,@description,@phone)
Upvotes: 4