How can I get the primary key in VIEW (a key that is independent of the source tables)

I create a VIEW OF 3 TABLES. Each TABLE has a primary key. However, in VIEW, in order to have a primary key, I will have to use a composite primary key (combination of primary keys 3 TABLES).

However, I would like to add a column to VIEW as a primary key that is created only for VIEW purposes. As part of the definition of VIEW, it must be UNIQUE (auto-increment, since it will be mainly INT). How can i achieve this?

I am using MySQL 5.1

+3
source share
4 answers

You can use various methods to insert a unique identifier in the data of the form, for example:

SELECT @rownum:=@rownum+1 as id, mytable.*
FROM (SELECT @rownum:=0) r, mytable;

, .

?

0

SELECT @rownum:=@rownum+1 as id, mytable.*
FROM (SELECT @rownum:=0) r, mytable;

- mysql, sub-select FROM. .

+10

- mysql , .

+3

- . .

... , ( )

(although I say SQL Server ... I'm not sure how this translates to MySQL)

0
source

Source: https://habr.com/ru/post/1726745/


All Articles