Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I declare auto increment variable in the virtual table of stored procedure

I have a stored procedure like this

create procedure onedata

as

begin

declare @input_data table (Id int NOT NULL AUTO_INCREMENT, name varchar(500) . .... )

insert into @input_data .....
....

end

But i am not able to declare Id to be AUTO_INCREMENT.It showing some error.
Please suggest some solution.

Thanks in advance

like image 966
Linnet Avatar asked Sep 21 '12 11:09

Linnet


2 Answers

This depends on the variety of SQL you are using.

For SQL Server

 declare @input_data table (Id int NOT NULL identity(1,1), name varchar(50))
like image 50
podiluska Avatar answered Oct 11 '22 14:10

podiluska


From your syntax, I'm guessing you are using SQL Server. If so, use identity instead of auto_increment:

declare @input_data table (Id int primary key identity, ... )
like image 33
Andomar Avatar answered Oct 11 '22 12:10

Andomar