Subject Re: [firebird-support] Primary key is ignored
Author Martijn Tonies
Hello Rick,

> Does anyone know why a primary key would not be used?

If you restore a database without turning "ON" the indices,
this might be the case.

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com


> (originally sent to wrong group)
>
> I used a stored procedure to import a lot of data, and got quite a
> surprise when I viewed it. Every imported record was in the table,
> including duplicates! Looking at the statistics for the primary key, it
> shows that it wasn't used. I wasn't aware that a PK could be turned
> off, or how to turn it back on now that it's off. Gfix -v -n didn't
> return any messages.
>
> CREATE TABLE MDDB_GPI
> (
> GPI D_GPI NOT NULL,
> GENERICNAME VARCHAR( 60) NOT NULL,
> CONSTRAINT PK_MDDB_GPI PRIMARY KEY (GPI)
> );
>
> select count(gpi) from MDDB_GPI
> 100820
> select count(distinct gpi) from MDDB_GPI
> 10169
>
> CREATE PROCEDURE GPI_INS_UPDT (
> GPI Decimal(14,0),
> GENERICNAME VarChar(60))
> AS
> BEGIN
> INSERT INTO MDDB_GPI (
> GPI,
> GENERICNAME)
> VALUES (
> :GPI,
> :GENERICNAME);
> WHEN SQLCODE -803 DO
> UPDATE MDDB_GPI SET
> GENERICNAME = :GENERICNAME
> WHERE
> GPI = :GPI;
> END