Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi set identity_insert (https://www.delphipraxis.net/13142-set-identity_insert.html)

Sandra 11. Dez 2003 17:53


set identity_insert
 
[sql]

Hallo Leute,


Ich habe mehrere bestehende Tabellen in einer MYSQL-DB, welche ich in eine SQL-DB transferiert werden sollen.
Mein Problem ist, dass ich einmal die Daten aus MYSQL mit insert in die neuen Tabellen einfügen möchte und wenn neue kommen diese mit identity(1,1) hochgezählt werden sollen. Um das zu realisieren habe ich einen SET-Befehl eingefügt (SET IDENTITY_INSERT tabellenname ON). Für eine Tabelle funktioniert dies auch alles.
Jetzt habe ich aber an die 20 Tabellen und bekomme die Meldung, das ich diesen Set-Befehl nur auf eine Tabelle anwenden kann.
Wie bekomme ich es hin, das bei den anderen Tabellen sowohl die Daten aus Mysql eingefügt werden und gleichzeitig bei neuen Daten diese hochgezählt werden? :gruebel:


Wäre super,wenn mir jemand weiter helfen könnte.

Sandra

SirThornberry 11. Dez 2003 18:46

Re: set identity_insert
 
Wenn ich dich recht verstanden hab exportierst du die datensätze ja erst. Da gäbe es die Möglichkeit einfach ein Delphiprogramm drüber zu jagen was doppelte zeilen sucht... Wozu dient das ganze (als das mitzählen)? Vielleicht gibt es ja für das problem noch eine ganz andere Lösung

Marcel Gascoyne 12. Dez 2003 06:17

Re: set identity_insert
 
Du kannst SET IDENTITY_INSERT immer nur auf eine Tabelle zur Zeit anwenden. Steht auch so in der Doku:

Zitat:

SET IDENTITY_INSERT
Allows explicit values to be inserted into the identity column of a table.

Syntax
SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }

Arguments
database

Is the name of the database in which the specified table resides.

owner

Is the name of the table owner.

table

Is the name of a table with an identity column.

Remarks
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.

If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value.

The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time.
Ich würde mal versuchen die Daten zuerst in eine temporäre Tabelle zu importieren und dort die Werte, z.b. über eine Stored Procedure, zu Ändern. Danach schreibst Du alles in die echten Tabellen rein.

Gruß,
Marcel


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz