× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Is there some way to use SQL to create a table LIKE another including the
primary key?

This doesn't work
CREATE TABLE mytbl2
LIKE mytbl1
PRIMARY KEY (mykey);

The manual seems to imply it's possible with a copy option...
"The implicit definition does not include any other optional attributes of
the identified table or view. For example, the new table does not
automatically include primary keys, foreign keys, or triggers. The new
table has these and other optional attributes only if the optional clauses
are explicitly specified."

But I don't see any copy option that mentions primary keys...

CRTDUPOBJ and CPYF are not options as the table being copied has a long
name.

Of course I can ALTER TABLE to add the primary key, but it'd be nice to
know if there was a way to include the primary key from the get-go.

Thanks!

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.