Attribute _id and id in Database

1

When creating a database either externally or using java code, we must create an attribute Primary key Autoincrement called _id .

With which, if I have in my relational database a id_producto in a table called Productos and I wish that id_producto is also Primary key and Autoincrement I can not because the attribute _id is already Primary key with which the Primary key of the table would be composed.

How can this be managed?

    
asked by aldakur 09.11.2016 в 13:31
source

2 answers

3

It is not possible to create multiple primary keys in a table.

Use a unique index has the same operation as a primary key:

CREATE UNIQUE INDEX pkindex ON "table1"("field1","field2");
    
answered by 10.11.2016 / 01:46
source
1

If I'm not wrong, this is not possible with SQLite however, you can create a UNIQUE INDEX that in essence, is the same as a Primary key

CREATE UNIQUE INDEX primary_key ON "tu_tabla"("_id","producto_id");
    
answered by 09.11.2016 в 13:37