6

is there a way to generate the CREATE TABLE code from an existing table in a Derby database? Or a simple way to gather the necessary table information?

5 Answers 5

5

You can try using the dblook tool to dump an Apache Derby database table into a sql file.

Sign up to request clarification or add additional context in comments.

Comments

1

If you just want the CREATE-statement to recreate the table, this works for me:

CREATE TABLE new_table AS SELECT * FROM old_table WITH NO DATA;

But this does not help if you really want the CREATE-statement for some other purpose than creating a similar table.

Comments

1

Well, this question is 6 years old, but here the screen shot below shows an easy way to do what you want. I hope you haven't been waiting. ;)

Right click on the table you're interested in and select Scripts -> Create TableScript.

Create Table screen shot

When you choose this menu item, you will get a window containing SQL, e.g.

CREATE TABLE "JOOMP"."METRICLEVELS"
(
   LEVELID int NOT NULL,
   LEVELNAME varchar(30) NOT NULL
)
;

If you also want SQL that will populate the table with the existing data, use Scripts -> Create Data Script. For this example, you will get:

INSERT INTO "JOOMP"."METRICLEVELS" (LEVELID,LEVELNAME) VALUES (2,'Project');
INSERT INTO "JOOMP"."METRICLEVELS" (LEVELID,LEVELNAME) VALUES (3,'Package Fragment Root');
INSERT INTO "JOOMP"."METRICLEVELS" (LEVELID,LEVELNAME) VALUES (4,'Package Fragment');
INSERT INTO "JOOMP"."METRICLEVELS" (LEVELID,LEVELNAME) VALUES (5,'Compilation Unit');
INSERT INTO "JOOMP"."METRICLEVELS" (LEVELID,LEVELNAME) VALUES (7,'Type');
INSERT INTO "JOOMP"."METRICLEVELS" (LEVELID,LEVELNAME) VALUES (9,'Method');

Comments

0

I don't have any experience in using derby but you could try to use JDBC API to gather database metadata

1 Comment

Take a look at the SchemaCrawler API to get at the table metadata easily. (Sualeh Fatehi, SchemaCrawler)
0

This works fine in MySQL if you want the CREATE statement.

SHOW CREATE TABLE `table_name`

See mysql doc for more information

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.