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

问题描述 投票:3回答:4

我有这个SQL查询

1 : show tables
2 : desc tablename

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

如何在德比中编写这些查询?

我想检查表的模式是否是主键。

如何在websphere中检查它

sql database derby
4个回答
4
投票

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

这是“描述”的文档: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中运行它们。


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**

0
投票
    describe name_table;

它有效,它显示了您想知道的表的所有描述,列和功能。


-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();
}
© www.soinside.com 2019 - 2024. All rights reserved.