Rael Bauer <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
> 1. with sqlite Is it possible to have a primary key made up of 2 fields?
> (If so how...)
> (from firebird:
> ALTER TABLE "table1" ADD CONSTRAINT PK_TABLE1 PRIMARY KEY
> ("field1","field2");)
>
>
> 2. Is it possible to add a primary key with an "ALTER" statement like:
> ALTER TABLE "table1" ADD CONSTRAINT PK_TABLE1 PRIMARY KEY ("field1");
>
You can have a composite primary key in SQLite, but you
have to create the key when you create the table:
CREATE TABLE example1(
field1 FLOAT,
field2 TEXT,
PRIMARY KEY(field1, field2)
);
You cannot create the primary key after the fact using ALTER TABLE.
On the other hand, you can create a UNIQUE INDEX after the fact
which has essentially the same effect as a PRIMARY KEY:
CREATE UNIQUE INDEX pk_index ON "table1"("field1","field2");
--
D. Richard Hipp <[EMAIL PROTECTED]>
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users