implicit PK
Posted in 2010
Topics: Storage & Space Management, Stored Procedures & SPL
Hi guys!
Does anybody know how can I do to change an implicit PK to an explicit PK for
all tables in a database automatically? I have several databases (about 50)
that uses implicit PK on the tables and I need to detach them using a SQL
script or a SPL for all tables in database.
Example:
create table "informix".tbgrupoexcecao
(
ems_numero integer not null ,
pri_grupo smallint,
primary key (pri_grupo)
);
I need to change to this;
create table "informix".tbgrupoexcecao
(
ems_numero integer not null ,
pri_grupo smallint
);
create unique index ix_01 on "informix".tbgrupoexcecao
(pri_grupo) using btree in dbspace_x;
I appreciate any help.
Thanks in advance,
Alberto.
That will be VERY hard to do...
You'd need to recreate all the indexes. But that will drop the foreign keys
that reference the table.
So you'd have to gather all foreign keys, drop all primary keys, recreate
all primary keys, recreate all foreign keys....
And make sure nobody touches the database.
Do you really to do that in your database? Or do you just need a schema
script with the changes you mention?
Regards.
On Tue, Mar 9, 2010 at 10:40 AM, ALBERTO ROMEU PESSONIO FILHO <
arfilho@orizonbrasil.com.br> wrote:
> Hi guys!
>
> Does anybody know how can I do to change an implicit PK to an explicit PK
> for
> all tables in a database automatically? I have several databases (about 50)
> that uses implicit PK on the tables and I need to detach them using a SQL
> script or a SPL for all tables in database.
>
> Example:
>
> create table "informix".tbgrupoexcecao
> (
>
> ems_numero integer not null ,
>
> pri_grupo smallint,
>
> primary key (pri_grupo)
> );
>
> I need to change to this;
>
> create table "informix".tbgrupoexcecao
> (
>
> ems_numero integer not null ,
>
> pri_grupo smallint
> );
>
> create unique index ix_01 on "informix".tbgrupoexcecao
> (pri_grupo) using btree in dbspace_x;>
> I appreciate any help.
> Thanks in advance,
> Alberto.
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--
Fernando Nunes
Portugal
http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
--0016e6d64c238b9ffb04815cb514
Hi,
as already mentioned you must take care not to loose schema objects (e.g.
foreign keys) and you probably will need an application downtime (e.g to avoid
duplicates after dropping the old primary key).
Another possible problem: It might take a very long time to drop an attached
index (implicit primary key). Sometimes it is faster to copy the table and
create the primary key afterwards.
Regards,
Andreas Kutsche
>
-------------------------------------------
SPAR Österreichische Warenhandels-AG
Hauptzentrale
A - 5015 Salzburg, Europastrasse 3
FN 34170 a
Tel: +43 662 4470 84923
Fax:
Mobile: +43 664 6259575
E-Mail: Andreas.KUTSCHE@spar.at
Internet: http://www.spar.at
Wichtiger Hinweis: Der Inhalt dieser E-Mail kann vertrauliche und rechtlich
geschützte Informationen, insbesondere Betriebs- oder Geschäftsgeheimnisse,
enthalten, zu deren Geheimhaltung der Empfänger verpflichtet ist. Die
Informationen in dieser E-Mail sind ausschließlich für den Adressaten
bestimmt. Sollten Sie die E-Mail irrtümlich erhalten haben so ersuchen wir
Sie, die Nachricht von Ihrem System zu löschen und sich mit uns in Verbindung
zu setzen.
Über das Internet versandte E-Mails können leicht manipuliert oder unter
fremdem Namen erstellt werden. Daher schließen wir die rechtliche
Verbindlichkeit der in dieser Nachricht enthaltenen Informationen aus. Der
Inhalt der E-Mail ist nur rechtsverbindlich, wenn er von uns schriftlich
bestätigt und gezeichnet wird.
Sollte trotz der von uns verwendeten Virus-Schutzprogramme durch die Zusendung
von E-Mails ein Virus in Ihre Systeme gelangen, haften wir nicht für evtl.
hieraus entstehende Schäden.
Wir danken für Ihr Verständnis.
Important notice: The contents of this e-mail may contain confidential and
legally protected information that is in particular related to operational and
trade secrets, which the recipient is obliged to treat as confidential. The
information in this e-mail is made available exclusively for use by the
addressee. In the event that the e-mail may have been sent to you in error, we
would ask you to kindly delete this communication from your system and to
contact us.
E-mails sent via the Internet can be easily manipulated or sent out under
someone else's name. We therefore do not accept legal liability for the
information contained in this communication. The contents of the e-mail are
only legally binding if they have been confirmed and signed by us in writing.
If, in spite of our using Antivirus protection software, a virus may have
penetrated your system through the sending of this e-mail, we do not accept
liability for any damage that may possibly arise as a result of this.
We trust that you appreciate our position.
-------------------------------------------
-----Ursprüngliche Nachricht-----
> Von: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] Im Auftrag von
> Fernando Nunes
> Gesendet: Dienstag, 9. März 2010 12:45
> An: ids@iiug.org
> Betreff: Re: implicit PK [19279]
>
> That will be VERY hard to do...
> You'd need to recreate all the indexes. But that will drop the foreign
> keys
> that reference the table.
> So you'd have to gather all foreign keys, drop all primary keys, recreate
> all primary keys, recreate all foreign keys....
> And make sure nobody touches the database.
>
> Do you really to do that in your database? Or do you just need a schema
> script with the changes you mention?
>
> Regards.
>
> On Tue, Mar 9, 2010 at 10:40 AM, ALBERTO ROMEU PESSONIO FILHO <
> arfilho@orizonbrasil.com.br> wrote:
>
> > Hi guys!
> >
> > Does anybody know how can I do to change an implicit PK to an explicit
> PK
> > for
> > all tables in a database automatically? I have several databases (about
> 50)
> > that uses implicit PK on the tables and I need to detach them using a
> SQL
> > script or a SPL for all tables in database.
> >
> > Example:
> >
> > create table "informix".tbgrupoexcecao
> > (
> >
> > ems_numero integer not null ,
> >
> > pri_grupo smallint,
> >
> > primary key (pri_grupo)
> > );
> >
> > I need to change to this;
> >
> > create table "informix".tbgrupoexcecao
> > (
> >
> > ems_numero integer not null ,
> >
> > pri_grupo smallint
> > );
> >
> > create unique index ix_01 on "informix".tbgrupoexcecao
> > (pri_grupo) using btree in dbspace_x;> >
> > I appreciate any help.
> > Thanks in advance,
> > Alberto.
> >
> >
> >
> >
> **************************************************************************
> *****
> > Forum Note: Use "Reply" to post a response in the discussion forum.
> >
> >
>
> --
> Fernando Nunes
> Portugal
>
> http://informix-technology.blogspot.com
> My email works... but I don't check it frequently...
>
> --0016e6d64c238b9ffb04815cb514
>
>
> **************************************************************************
> *****
> Forum Note: Use "Reply" to post a response in the discussion forum.
You could use Art's magical 'myschema' which will create the schema with
separate files for creating tables and another one for creating all indices.
Available at www.iiug.org tools. An awk script could then piece together
whatever you want.
Bob
----- Original Message -----
From: "Andreas.KUTSCHE@spar.at" <andreas.kutsche@spar.at>
To: ids@iiug.org
Sent: Tuesday, March 9, 2010 7:57:09 AM GMT -05:00 US/Canada Eastern
Subject: AW: implicit PK [19281]
Hi,
as already mentioned you must take care not to loose schema objects (e.g.
foreign keys) and you probably will need an application downtime (e.g to avoid
duplicates after dropping the old primary key).
Another possible problem: It might take a very long time to drop an attached
index (implicit primary key). Sometimes it is faster to copy the table and
create the primary key afterwards.
Regards,
Andreas Kutsche
>
-------------------------------------------
SPAR sterreichische Warenhandels-AG
Hauptzentrale
A - 5015 Salzburg, Europastrasse 3
FN 34170 a
Tel: +43 662 4470 84923
Fax:
Mobile: +43 664 6259575
E-Mail: Andreas.KUTSCHE@spar.at
Internet: http://www.spar.at
Wichtiger Hinweis: Der Inhalt dieser E-Mail kann vertrauliche und rechtlich
geschtzte Informationen, insbesondere Betriebs- oder Geschftsgeheimnisse,
enthalten, zu deren Geheimhaltung der Empfnger verpflichtet ist. Die
Informationen in dieser E-Mail sind ausschlielich fr den Adressaten
bestimmt. Sollten Sie die E-Mail irrtmlich erhalten haben so ersuchen wir
Sie, die Nachricht von Ihrem System zu lschen und sich mit uns in Verbindung
zu setzen.
ber das Internet versandte E-Mails knnen leicht manipuliert oder unter
fremdem Namen erstellt werden. Daher schlieen wir die rechtliche
Verbindlichkeit der in dieser Nachricht enthaltenen Informationen aus. Der
Inhalt der E-Mail ist nur rechtsverbindlich, wenn er von uns schriftlich
besttigt und gezeichnet wird.
Sollte trotz der von uns verwendeten Virus-Schutzprogramme durch die Zusendung
von E-Mails ein Virus in Ihre Systeme gelangen, haften wir nicht fr evtl.
hieraus entstehende Schden.
Wir danken fr Ihr Verstndnis.
Important notice: The contents of this e-mail may contain confidential and
legally protected information that is in particular related to operational and
trade secrets, which the recipient is obliged to treat as confidential. The
information in this e-mail is made available exclusively for use by the
addressee. In the event that the e-mail may have been sent to you in error, we
would ask you to kindly delete this communication from your system and to
contact us.
E-mails sent via the Internet can be easily manipulated or sent out under
someone else's name. We therefore do not accept legal liability for the
information contained in this communication. The contents of the e-mail are
only legally binding if they have been confirmed and signed by us in writing.
If, in spite of our using Antivirus protection software, a virus may have
penetrated your system through the sending of this e-mail, we do not accept
liability for any damage that may possibly arise as a result of this.
We trust that you appreciate our position.
-------------------------------------------
-----Ursprngliche Nachricht-----
> Von: ids-bounces@iiug.org [mailto:ids-bounces@iiug.org] Im Auftrag von
> Fernando Nunes
> Gesendet: Dienstag, 9. Mrz 2010 12:45
> An: ids@iiug.org
> Betreff: Re: implicit PK [19279]
>
> That will be VERY hard to do...
> You'd need to recreate all the indexes. But that will drop the foreign
> keys
> that reference the table.
> So you'd have to gather all foreign keys, drop all primary keys, recreate
> all primary keys, recreate all foreign keys....
> And make sure nobody touches the database.
>
> Do you really to do that in your database? Or do you just need a schema
> script with the changes you mention?
>
> Regards.
>
> On Tue, Mar 9, 2010 at 10:40 AM, ALBERTO ROMEU PESSONIO FILHO <
> arfilho@orizonbrasil.com.br> wrote:
>
> > Hi guys!
> >
> > Does anybody know how can I do to change an implicit PK to an explicit
> PK
> > for
> > all tables in a database automatically? I have several databases (about
> 50)
> > that uses implicit PK on the tables and I need to detach them using a
> SQL
> > script or a SPL for all tables in database.
> >
> > Example:
> >
> > create table "informix".tbgrupoexcecao
> > (
> >
> > ems_numero integer not null ,
> >
> > pri_grupo smallint,
> >
> > primary key (pri_grupo)
> > );
> >
> > I need to change to this;
> >
> > create table "informix".tbgrupoexcecao
> > (
> >
> > ems_numero integer not null ,
> >
> > pri_grupo smallint
> > );
> >
> > create unique index ix_01 on "informix".tbgrupoexcecao
> > (pri_grupo) using btree in dbspace_x;> >
> > I appreciate any help.
> > Thanks in advance,
> > Alberto.
> >
> >
> >
> >
> **************************************************************************
> *****
> > Forum Note: Use "Reply" to post a response in the discussion forum.
> >
> >
>
> --
> Fernando Nunes
> Portugal
>
> http://informix-technology.blogspot.com
> My email works... but I don't check it frequently...
>
> --0016e6d64c238b9ffb04815cb514
>
>
Not automated, no. You will have to drop all of your tables with implicit
constraints (since they have constraint names that are actually illegal so
you can't drop the constraints) but you can make it easier to do:
- Get my packages utils2_ak and utils3_ak from the IIUG Software
Repository
- Build the utilities in utils2_ak to get the myschema utility
- Run myschema with the -l option (makes the output compatible with
dbexport/dbimport) into a file named <databasename>.sql
- Dbexport your database.
- Substitute the output file from myschema above for the one in the
dbexport <databasename>.exp directory
- Drop or rename your original database.
- dbimport the database using the <databasename>.sql file built by
myschema.
Voila!
Art
Art S. Kagel
Advanced DataTools (www.advancedatatools.com)
IIUG Board of Directors (art@iiug.org)
See you at the 2010 IIUG Informix Conference
April 25-28, 2010
Overland Park (Kansas City), KS
www.iiug.org/conf
Disclaimer: Please keep in mind that my own opinions are my own opinions and
do not reflect on my employer, Advanced DataTools, the IIUG, nor any other
organization with which I am associated either explicitly, implicitly, or by
inference. Neither do those opinions reflect those of other individuals
affiliated with any entity with which I am affiliated nor those of the
entities themselves.
On Tue, Mar 9, 2010 at 5:40 AM, ALBERTO ROMEU PESSONIO FILHO <
arfilho@orizonbrasil.com.br> wrote:
> Hi guys!
>
> Does anybody know how can I do to change an implicit PK to an explicit PK
> for
> all tables in a database automatically? I have several databases (about 50)
> that uses implicit PK on the tables and I need to detach them using a SQL
> script or a SPL for all tables in database.
>
> Example:
>
> create table "informix".tbgrupoexcecao
> (
>
> ems_numero integer not null ,
>
> pri_grupo smallint,
>
> primary key (pri_grupo)
> );
>
> I need to change to this;
>
> create table "informix".tbgrupoexcecao
> (
>
> ems_numero integer not null ,
>
> pri_grupo smallint
> );
>
> create unique index ix_01 on "informix".tbgrupoexcecao
> (pri_grupo) using btree in dbspace_x;>
> I appreciate any help.
> Thanks in advance,
> Alberto.
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--00151750df1644dc16048165bb80