【发布时间】:2013-12-07 04:49:50
【问题描述】:
我有这个 SQL 查询
1 : show tables
2 : desc tablename
但这似乎不是德比中的语法。
如何在 derby 中编写这些查询??
我想检查表的架构是否是主键。
如何在 websphere 中检查
【问题讨论】:
我有这个 SQL 查询
1 : show tables
2 : desc tablename
但这似乎不是德比中的语法。
如何在 derby 中编写这些查询??
我想检查表的架构是否是主键。
如何在 websphere 中检查
【问题讨论】:
describe name_table;
它有效,它显示了您想知道的表格的所有描述、列和功能。
【讨论】:
我知道没有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();
}
【讨论】:
通过查询显示表格(no IJ):
select st.tablename from sys.systables st LEFT OUTER join sys.sysschemas ss on (st.schemaid = ss.schemaid) where ss.schemaname ='APP'
通过查询显示列(no IJ):
select * from sys.syscolumns where referenceid = (select tableid from sys.systables where tablename = 'THE_TABLE') order by columnnumber**strong text**
【讨论】:
严格来说,这不是 SQL。相反,这些是 IJ 命令,必须由 IJ 工具处理。
这是“描述”的文档:http://db.apache.org/derby/docs/10.10/tools/rtoolsijcomrefdescribe.html
这里是“显示表格”的文档:http://db.apache.org/derby/docs/10.10/tools/rtoolsijcomrefshow.html
您不在 Websphere 中运行这些命令,而是在 IJ 中运行它们。
【讨论】: