MySQL Forums
Forum List  »  Italian

Campo univoco numerato in una View
Posted by: Claudio D'Alicandro
Date: January 22, 2010 03:53AM

Salve, mi sto perdendo in un bicchiere d'acqua, spero che qualcuno mi possa aiutare:
ho bisogno di una view che contenga, oltre ai vari dati reperibili nelle tabelle, un numero identificativo che sia l'indice della row, ma che si comporti come un AUTO_INCREMENT quando fa parte di una PRIMARY KEY composta, ossia, citando la documentazione,

CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
) ENGINE=MyISAM;

INSERT INTO animals (grp,name) VALUES
('mammal','dog'),('mammal','cat'),
('bird','penguin'),('fish','lax'),('mammal','whale'),
('bird','ostrich');

SELECT * FROM animals ORDER BY grp,id;

Which returns:

+--------+----+---------+
| grp | id | name |
+--------+----+---------+
| fish | 1 | lax |
| mammal | 1 | dog |
| mammal | 2 | cat |
| mammal | 3 | whale |
| bird | 1 | penguin |
| bird | 2 | ostrich |
+--------+----+---------+

Il problema รจ che le view non hanno primary key!

Options: ReplyQuote


Subject
Views
Written By
Posted
Campo univoco numerato in una View
4069
January 22, 2010 03:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.