Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread CREATE TABLE AS
Mon, Dec 31 2007 10:44 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Can someone give me an example of the syntax to clone a table indices, data, constraints and all?


Roy Lambert
Mon, Dec 31 2007 7:43 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Can someone give me an example of the syntax to clone a table indices,
data, constraints and all? >>

Use this;

SCRIPT (NewTable VARCHAR, TableToCopy VARCHAR)
BEGIN
  EXECUTE IMMEDIATE 'CREATE TABLE "'+NewTable+'"
                    (
                    LIKE "'+TableToCopy+'" INCLUDING IDENTITY INCLUDING
DEFAULTS INCLUDING GENERATED
                    )';
  EXECUTE IMMEDIATE 'INSERT INTO "'+NewTable+'" SELECT * FROM
"'+TableToCopy+'"';
END

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Jan 1 2008 7:04 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


I saw those options in the manual, but didn't, and still don't understand what they each mean, and I certainly didn't figure any of them to mean indices.

Is there a reason for the LIKE rather than AS SELECT .. WITH DATA?

Roy Lambert
Tue, Jan 1 2008 12:44 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< I saw those options in the manual, but didn't, and still don't understand
what they each mean, and I certainly didn't figure any of them to mean
indices. >>

Actually, you're correct.  For some reason I thought that it would copy at
least the constraints also, but it isn't doing so.  I'll have to
double-check on this, because it may be a bug (the constraints).  At the
very least, what I'll do is include additional options for including the
constraints and/or indexes.

<< Is there a reason for the LIKE rather than AS SELECT .. WITH DATA? >>

Yes.  SELECT..WITH DATA does not copy default values, identify attributes,
etc.  It only copies the basic column information like the data type.

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Jan 1 2008 1:23 PMPermanent Link

"Ole Willy Tuv"
Tim,

<< Actually, you're correct.  For some reason I thought that it would copy
at least the constraints also, but it isn't doing so.  I'll have to
double-check on this, because it may be a bug (the constraints).  >>

My guess is that you excluded the constraints because this is how the LIKE
clause is defined in the standard SQL specification.

<< At the very least, what I'll do is include additional options for
including the constraints and/or indexes. >>

Implementing support for constraints and indexes as additional options
(vendor extension) would be a good way IMO.

Ole Willy Tuv
Wed, Jan 2 2008 4:00 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Ole,

<< My guess is that you excluded the constraints because this is how the
LIKE clause is defined in the standard SQL specification. >>

Yes, that is likely. Smiley

<< Implementing support for constraints and indexes as additional options
(vendor extension) would be a good way IMO. >>

Yes, there needs to be a way to copy an entire table structure rather
easily.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image