如何在DERBY DB中描述和显示表格?

时间:2013-11-22 10:31:22

标签: sql database derby

我有这个SQL查询

1 : show tables
2 : desc tablename

但这似乎不是德比中的语法。

如何在derby中编写这些查询?

我想检查表的架构是否是主键。

如何在websphere中检查

4 个答案:

答案 0 :(得分:4)

严格来说,这不是SQL。相反,这些是IJ命令,必须由IJ工具处理。

以下是“describe”的文档:http://db.apache.org/derby/docs/10.10/tools/rtoolsijcomrefdescribe.html

以下是“show tables”的文档:http://db.apache.org/derby/docs/10.10/tools/rtoolsijcomrefshow.html

您不在Websphere中运行这些命令,而是在IJ中运行它们。

答案 1 :(得分:2)

通过查询显示表格(没有IJ ):

select st.tablename  from sys.systables st LEFT OUTER join sys.sysschemas ss on (st.schemaid = ss.schemaid) where ss.schemaname ='APP'

通过查询显示列(没有IJ ):

select * from sys.syscolumns where referenceid = (select tableid from sys.systables where tablename = 'THE_TABLE') order by columnnumber**strong text**

答案 2 :(得分:0)

    describe name_table;

它起作用了,它显示了您想知道的表的所有描述以及列和功能。

答案 3 :(得分:-1)

在没有JOINS等的情况下,我知道有两种方法:

try {

    Connection databaseConnection;
    //Establish Connection Through Embedded Or Local Install
    DatabaseMetaData metaDataForDatabaseConnection = databaseConnection.getMetaData();
    ResultSet resultSetForTableNames = metaDataForDatabaseConnection.getTables(null, null, null, new String[]{"TABLE"});


    while (resultSetForTableNames.next()) {
        System.out.println(resultSetForTableNames.getString(3));
    }

    //Close Resources As Necessary
}
catch (Exception e) {
    e.printStackTrace();
}

并且:

try {   

    Connection databaseConnection;
    //Establish Connection Through Embedded Or Local Install
    Statement databaseStatement = databaseConnection.createStatement();
    ResultSet resultSet = databaseStatement.executeQuery("SELECT SYS.SYSTABLES.TABLENAME FROM SYS.SYSTABLES WHERE SYS.SYSTABLES.TABLETYPE = \'T\'");


    while (resultSet.next()) {

        System.out.println(resultSet.getString("TABLENAME"));
    }

    //Close Resources As Necessary
}
catch (Exception e) {
    e.printStackTrace();
}