【问题标题】:how to describe and show table in DERBY DB?如何在 DERBY DB 中描述和显示表格?
【发布时间】:2013-12-07 04:49:50
【问题描述】:

我有这个 SQL 查询

1 : show tables
2 : desc tablename

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

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

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

如何在 websphere 中检查

【问题讨论】:

    标签: sql database derby


    【解决方案1】:
        describe name_table;
    

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

    【讨论】:

      【解决方案2】:

      我知道没有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();
      }
      

      【讨论】:

        【解决方案3】:

        通过查询显示表格(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**
        

        【讨论】:

        • 第一个命令允许获取表的全名,可以在 CLI 中修剪。这是一个强大的命令
        【解决方案4】:

        严格来说,这不是 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 中运行它们。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-09-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-06
          • 2018-09-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多