Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all tables in Derby DB

Tags:

java

sql

jdbc

derby

How do i delete all the tables in the schema on Apache Derby DB using JDBC?

like image 570
Shimi Bandiel Avatar asked Oct 05 '08 09:10

Shimi Bandiel


People also ask

How do I delete a row in Derby database?

Apache Zeppelin - Big Data Visualization ToolThe DELETE statement is used to delete rows of a table. Just like the UPDATE statement, Apache Derby provides two types of Delete (syntax): searched delete and positioned delete. The searched delete statement deletes all the specified columns of a table.

Does Derby use SQL?

Derby does not have an SQL create database command. ; The semicolon is the ij command terminator. Create a table with two columns using standard SQL.

How do I backup my Derby database?

Summary. Backing up a Derby database is pretty easy. Just call SYSCS_UTIL. SYSCS_BACKUP_DATABASE('/location/of/the/backup/') .


2 Answers

Thanks are due to the blog:

Step 1:

Run the SQL statement, but don't forget to replace the schema name 'APP' with your your schema name in the 2 occurrences below:

SELECT
'ALTER TABLE '||S.SCHEMANAME||'.'||T.TABLENAME||' DROP CONSTRAINT '||C.CONSTRAINTNAME||';'
FROM
    SYS.SYSCONSTRAINTS C,
    SYS.SYSSCHEMAS S,
    SYS.SYSTABLES T
WHERE
    C.SCHEMAID = S.SCHEMAID
AND
    C.TABLEID = T.TABLEID
AND
S.SCHEMANAME = 'APP'
UNION
SELECT 'DROP TABLE ' || schemaname ||'.' || tablename || ';'
FROM SYS.SYSTABLES
INNER JOIN SYS.SYSSCHEMAS ON SYS.SYSTABLES.SCHEMAID = SYS.SYSSCHEMAS.SCHEMAID
where schemaname='APP';

Step 2:

The result of the above execution is a set of SQL statements, copy them to the SQL editor, execute them, then the constraints and the tables are dropped.

like image 131
Sym-Sym Avatar answered Oct 16 '22 14:10

Sym-Sym


For actual code that does this, check CleanDatabaseTestSetup.java in the Derby test suite section of the Derby distribution.

like image 43
Bryan Pendleton Avatar answered Oct 16 '22 13:10

Bryan Pendleton