Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi Problem bei Tadocommand (https://www.delphipraxis.net/133764-problem-bei-tadocommand.html)

R2009 8. Mai 2009 07:45

Datenbank: Access • Zugriff über: TADOconnect

Problem bei Tadocommand
 
Hi,
warum funktioniert das nicht:
ich versuche eine bestehende Tabelle zu kopieren.
Fehlermeldung: Fehler in SQL Syntax

Delphi-Quellcode:
procedure create_table_by_copy(s:TADOcommand;name:string);
begin
  (s as TADOcommand).CommandText:='CREATE TABLE test SELECT * FROM Liste_D';
  (s as TADOcommand).Execute;
end;
Vielen Dank im Vorraus.

JohannesK 8. Mai 2009 07:56

Re: Problem bei Tadocommand
 
Mit dem SQL-String versucht Du aus den Inhalten einer Tabelle eine neue Tabelle zu erzeugen. Geht natürlich nicht.
Die Felder einer Tabelle kannst Du auslesen mit
SQL-Code:
SHOW FIELDS FROM xyz
das CREATE Statement je nach verwendeter Datenbank mit
SQL-Code:
SHOW CREATE TABLE xyz
.

Du musst Dein Statement in zwei bis drei Schritte zerlegen: lesen der Definition, Änderung der Tabellenbezeichung mit stringreplace o.ä. und anlegen der neuen Tabelle.

R2009 8. Mai 2009 08:07

Re: Problem bei Tadocommand
 
Hi Johannes,
danke für deine Antwrt. Versteh ich nicht.
Hab im Internet folgendes gefunden:

Zitat:

SQL COPY TABLE Command
For backup and other requirements we often have to copy the data of a table or copy the total table structure with data. We can selectively copy the data of a MySQL table to a new table or copy the total data to a new table. We will learn here different techniques on how to do this.

We can copy a table structure and records to another new table. The CREATE TABLE command will create a table with same structure of the old table and add all the records. To export data to an existing table you can use insert command.
CREATE TABLE student2 SELECT * FROM student
This will create a new table class2 using the structure of the table class and will copy all the records from table class to our new table class2.
Hab ich was falsch verstanden oder wo ist was falsch?

Vielen Dank!

nahpets 8. Mai 2009 08:18

Re: Problem bei Tadocommand
 
Hallo,

das was in der Beschreibung für MySQL zum Create Table... steht, kann Access nicht.

Eventuell funktioniert ja
SQL-Code:
create table test as Select * from Liste_D
Aber da geht probieren über studieren. Weiß nicht, ob das zum Standard gehört und welche Datenbank das dann zusätzlich auch noch unterstützt.

Ralf Kaiser 8. Mai 2009 08:21

Re: Problem bei Tadocommand
 
Zitat:

Zitat von R2009
Zitat:

SQL COPY TABLE Command
For backup and other requirements we often have to copy the data of a table or copy the total table structure with data. We can selectively copy the data of a MySQL table to a new table or copy the total data to a new table. We will learn here different techniques on how to do this.
Hab ich was falsch verstanden oder wo ist was falsch?

In deinem ersten Beitrag hast du "Access" als Datenbank angegeben. Das was du da gefunden hast bezieht sich aber auf MySQL!!

Bernhard Geyer 8. Mai 2009 08:21

Re: Problem bei Tadocommand
 
was pasiert wenn die Query direkt in Access ausgeführt wird?

JohannesK 8. Mai 2009 08:52

Re: Problem bei Tadocommand
 
Hab das mal schnell ausprobiert und bekomme auch nur eine Fehlermeldung bei ADO und Mydac-Kompos.
Im MySQL-Handbuch ist es so dokumentiert:
Zitat:

mysql> CREATE TABLE test (a INT NOT NULL AUTO_INCREMENT,
-> PRIMARY KEY (a), KEY(b))
-> TYPE=MyISAM SELECT b,c FROM test2;

This creates a MyISAM table with three columns, a, b, and c. Notice that the columns from the SELECT statement are appended to the right side of the table, not overlapped onto it.
Möglicherweise nur im Konsolenmodus möglich, da funktioniert es. Vielleicht bleibt Dir doch nur das zerlegen.

:oops: völlig überlesen dass es sich um Access handelt, sorry


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:18 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