user2804599
user2804599

Reputation: 97

Get table schema or structure in netbeans, derby

I've been creating a database in derby/netbeans. And I'd like to output the structure of the database, not just exporting the whole database. How do I do this?

I've tried both "EXEC 'table name';" which returned "Error code -1, SQL state 42X01: Syntax error: Encountered "exec" at line 1, column 1." and "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'table name';" which returned "Error code -1, SQL state 42Y07: Schema 'INFORMATION_SCHEMA' does not exist".

I've read on multiple forums that this should work, do you guys have any idea what I'm doing wrong?

Upvotes: 5

Views: 15303

Answers (4)

user1643352
user1643352

Reputation: 2917

The simplest with NetBeans (8.0, perhaps with the previous versions too): "View Data..." of the table, right click on the data and choose "Show SQL Script for CREATE". You can copy the SQL script.

Upvotes: 2

Łukasz Pecyna
Łukasz Pecyna

Reputation: 19

The easiest way is to enter the command: DESCRIBE table_name;

Upvotes: 0

Bryan Pendleton
Bryan Pendleton

Reputation: 16389

Another way to do this is to use the "dblook" utility: http://db.apache.org/derby/docs/10.10/getstart/tgsrunningdblook.html

Upvotes: 0

moskito-x
moskito-x

Reputation: 11968

GET TABLE STRUCTURE

select COLUMNNAME,COLUMNDATATYPE 
FROM sys.systables t, sys.syscolumns 
WHERE TABLEID = REFERENCEID and tablename = 'FRIENDS' 

enter image description here

Other fields you can use in select

  • COLUMNDEFAULT
  • COLUMNDEFAULTID
  • AUTOINCREMENTVALUE
  • AUTOINCREMENTSTART
  • AUTOINCREMENTINC

Inside Netbeans

Expand the Tables node under the sample database connection, right-click the table node and choose Grab Structure.

enter image description here

In the Grab Table dialog that opens, specify a location on your computer to save the grab file that will be created. Click Save.

The grab file records the table definition of the selected table. Expand the APP schema node under the Contact DB database connection, right-click the Tables node and choose Recreate Table to open the Recreate Table dialog box.

enter image description here

In the Recreate Table dialog box, navigate to the location where you saved the CUSTOMER grab file and click Open to open the Name the Table dialog box.

enter image description here

GET TABLES

A complete list.

select * from SYS.SYSTABLES;

enter image description here

Only TABLENAME

select TABLENAME from SYS.SYSTABLES where TABLETYPE='T'

enter image description here

Derby Table

Upvotes: 6

Related Questions