Question: I have a MySQL database from which a view is created. Is is possible to add an auto-incrementing id for each row in the view?

I tried

```
CREATE ALGORITHM=UNDEFINED DEFINER=`database_name`@`%` SQL SECURITY DEFINER VIEW `MyView` AS 
set @i = 0;
select  @i:=@i+1 as `id`
        ...

```

but that doesn't work in a View.

Answer: 
Sorry - you can't autoincrement in a VIEW (You could do this in a Stored Procedure though).

From the [MySQL Manual](http://dev.mysql.com/doc/refman/5.0/en/create-view.html):

> 
> A view definition is subject to the
>  following restrictions: The SELECT
>  statement cannot refer to system or
>  user variables.
> 
> 
>
try this,

```
create view view_st as
select row_number() over (order by column_st) id, column_st 
from table_st;

```