Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread How to create a new table from existing table structure?
Sat, Aug 25 2012 2:04 PMPermanent Link

Barry

I'd "like" to be able to execute:

create NewTable like OldTable;    -- This works in MySQL

but that doesn't work because EDB doesn't know how to interpret "Like".

I know I can execute:
create table NewTable as select * from OldTable with no data;

but of course that doesn't create the indexes or triggers.

Is there an easy way to use SQL to create a new table structure based on an existing table? I don't need the data, just the columns, indexes, and triggers.

TIA
Barry
Sat, Aug 25 2012 6:30 PMPermanent Link

Uli Becker

Barry,

> Is there an easy way to use SQL to create a new table structure based on an existing table? I don't need the data, just the columns, indexes, and triggers.

That was discussed earlier. At the moment it's not possible.

But there is an undocumented feature in EDBManager that will help you:

Just create an emypt script, drag a table from the treeview into the
body of the script, do the same with all indexes and triggers. That will
create the code you need very quickly.

Uli
Wed, Sep 5 2012 8:21 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Barry,

<< but that doesn't work because EDB doesn't know how to interpret "Like".
>>

Wrong syntax, use this instead:

CREATE TABLE NewTable
(
LIKE OldTable
)

That's the standard syntax, and allows you to do things like this:

CREATE TABLE NewTable
(
LIKE OldTable,
LIKE AnotherOldTable
)

However, there is one caveat - this will only copy the columns over and not
any constraints, etc.  You have to define those manually, at least for now.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Image