LoginSignup
1
1

More than 5 years have passed since last update.

全てのテーブルのレコード数をカウントする

Posted at
@GrabConfig(systemClassLoader = true)
@Grab('mysql:mysql-connector-java:5.1.31')
import groovy.sql.Sql

def db = Sql.newInstance("jdbc:mysql://localhost:3306/dbname", "root", "", "com.mysql.jdbc.Driver")

db.eachRow('show tables') { row ->
    def tableName = row[0]
    db.eachRow("select count(*) as cnt from " + tableName) {
        println "$tableName: $it.cnt"
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1