I want to insert @id value into Items table as auto increment.
Table Name= Items Columns= Code, Name.
The column Code does not allow null value and is unique but it has no auto increment, I tried to write query which will fill value (1,2,3,4,...) in column of Code as auto increment but it does not work
This is my query
DECLARE @id INT
SET @id = (select MAX(Code) from Items)
SET @id =@id+1
insert into Items (Code,Name) values(@id,'m')
This is the error
Msg 515, Level 16, State 2, Line 6 Cannot insert the value NULL into column 'Code', table 'Items'; column does not allow nulls. INSERT fails. The statement has been terminated.
I want @id to be inserted in column of Code as auto increment.
Please anyone can help me.