zoukankan      html  css  js  c++  java
  • mysql获取表列信息、主键信息

      /**
         * 获取物理表中已存在的列信息
         * @param tbName 表名
         * @return results 查询结果
         */
        fun getExistColumnInfo(tbName:String) :List<Record> {
            var sql = "select database() AS db_name"
            var dbNameRecord = Db.findFirst(sql)
            var existColSql = """
                 select COLUMN_NAME as name
                 from INFORMATION_SCHEMA.COLUMNS
                 where TABLE_SCHEMA=? and TABLE_NAME=?
                """
            var results = Db.find(existColSql, dbNameRecord.getStr("dbName"), tbName)
            return results
        }
    

      获取主键信息:

       /**
         * 获取物理表已存在的主键字段名
         * @param tbName 表名
         * @return results 查询结果
         */
        fun getExistPrimaryKeyFields(tbName: String) : List<Record>? {
            var sql = "select database() AS db_name"
            var dbNameRecord = Db.findFirst(sql)
            var existPKFiledsSql = """
                    SELECT
                        k.column_name,
                        t.table_name,
                        table_schema
                    FROM
                        information_schema.table_constraints t
                    JOIN information_schema.key_column_usage k USING (
                        constraint_name,
                        table_schema,
                        table_name
                    )
                    WHERE
                        t.constraint_type = 'PRIMARY KEY'
                    AND t.table_schema = ?
                    AND t.table_name = ?
                """
            var results = Db.find(existPKFiledsSql, dbNameRecord.getStr("dbName"), tbName)
            return results
        }
    

      

  • 相关阅读:
    一键java环境配置
    eclipse + tomcat7 + maven 配置过程
    eclipse/myeclipse link 方式安装插件
    eclipse maven plugin 插件 安装 和 配置
    Spring MVC 教程,快速入门,深入分析
    Spring MVC 框架搭建及详解
    Javassist介绍
    OO的奇妙冒险4
    OO的奇妙冒险3
    OO的奇妙冒险2
  • 原文地址:https://www.cnblogs.com/vae860514/p/9435610.html
Copyright © 2011-2022 走看看