Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Copy tables between databases
Sun, Oct 2 2011 12:34 PMPermanent Link

Hershcu Sorin

Hello

I saw this debate on previous threads but I can't figure what is the state
on the last version.

I want to create a copy from a table from one database to a second database
on the same session, without the data.
I know that I can create a sql statement using the reverse engeneering and
run it on the second database.

Can this be done using "create copy of table" on the run time?
Or can I use "create table like" statement?

Thanks
Sorin

Sun, Oct 2 2011 1:19 PMPermanent Link

Adam Brett

Orixa Systems

EDBMgr generates a CREATE Statement for every table each time you select it in the TreeView on the left of the screen.

It must be creating this script somehow.

Either it is running some clever code parsing the Configuration.TableColumns table, or the table definitions are hidden away somewhere else. You could check the source-code for EDBMgr and see how it does it.

Then all you have to do is use this trick, coupled with substituting in the database-names you need

USING Database1

USING Database2
Mon, Oct 3 2011 4:20 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Sorin


You can use the CREATE TABLE LIKE/AS but you have to make sure that the query/script is pointing to the target database and that the query fully qualifies (ie database.tablename) the source table.

You will have to do bit of manual coding to get the indices/triggers/constraints etc since these are not currently catered for.

The best approach would be a script to which you pass table and database names it can then construct a query to do the main creation and query the information tables to get the other data to build the rest of the bits.

Roy Lambert [Team Elevate]
Mon, Oct 3 2011 9:06 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Sorin,

<< I know that I can create a sql statement using the reverse engeneering
and run it on the second database. >>

You can access the reverse-engineering class (TEDBReverseEngineer located in
the edbutilcomps.pas unit in the \utilcomps subdirectory) via code if you
need to do so at runtime.  The code is fairly self-explanatory, but the
basic steps are:

1) Create the TEDBReverseEngineer object.

2) Set the TargetDatabase property to an already open TEDBDatabase component
(this is usually just the database that you want to reverse-engineer).

3) Call the GetTableSQL, etc. methods as necessary to get the DDL SQL for
creating the table, indexes, etc. and use the TEDBDatabase.Execute method of
the destination database to execute the DDL against that database.

<< Can this be done using "create copy of table" on the run time? Or can I
use "create table like" statement? >>

You can use CREATE TABLE with the LIKE clause, but it only handles the
columns and not the constraints, indexes, triggers, etc.:

CREATE TABLE MyTable
(
LIKE MyOtherDatabase.MyOtherTable
)

--
Tim Young
Elevate Software
www.elevatesoft.com
Image