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
You can try using the dblook tool to dump an Apache Derby database table into a sql file.
Comments
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.
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
I don't have any experience in using derby but you could try to use JDBC API to gather database metadata
1 Comment
This works fine in MySQL if you want the CREATE statement.
SHOW CREATE TABLE `table_name`
See mysql doc for more information
