zoukankan      html  css  js  c++  java
  • SQL-49 针对库中的所有表生成select count(*)对应的SQL语句

    题目描述

    针对库中的所有表生成select count(*)对应的SQL语句
    CREATE TABLE `employees` (
    `emp_no` int(11) NOT NULL,
    `birth_date` date NOT NULL,
    `first_name` varchar(14) NOT NULL,
    `last_name` varchar(16) NOT NULL,
    `gender` char(1) NOT NULL,
    `hire_date` date NOT NULL,
    PRIMARY KEY (`emp_no`));
    create table emp_bonus(
    emp_no int not null,
    recevied datetime not null,
    btype smallint not null);
    CREATE TABLE `dept_emp` (
    `emp_no` int(11) NOT NULL,
    `dept_no` char(4) NOT NULL,
    `from_date` date NOT NULL,
    `to_date` date NOT NULL,
    PRIMARY KEY (`emp_no`,`dept_no`));
    CREATE TABLE `dept_manager` (
    `dept_no` char(4) NOT NULL,
    `emp_no` int(11) NOT NULL,
    `from_date` date NOT NULL,
    `to_date` date NOT NULL,
    PRIMARY KEY (`emp_no`,`dept_no`));
    CREATE TABLE `salaries` (
    `emp_no` int(11) NOT NULL,
    `salary` int(11) NOT NULL,
    `from_date` date NOT NULL,
    `to_date` date NOT NULL,
    PRIMARY KEY (`emp_no`,`from_date`));
    输出格式:
    cnts
    select count(*) from employees;
    select count(*) from departments;
    select count(*) from dept_emp;
    select count(*) from dept_manager;
    select count(*) from salaries;
    select count(*) from titles;
    select count(*) from emp_bonus;

    SQL:

    select "select count(*) from "||name||";" as cnts
    from sqlite_master 
    where type='table'
    

      在 SQLite 系统表 sqlite_master 中可以获得所有表的索引,其中字段 name 是所有表的名字,而且对于自己创建的表而言,字段 type 永远是 'table'

  • 相关阅读:
    [题解]小X的液体混合
    [题解]图的遍历
    [模板]基本线段树操作
    C#中 Excel列字母与数字的相互转换
    Oracle 查询数据库表大小
    vi/vim 编辑、搜索、查找、定位
    Linux 中 sqlite3 基本操作
    MessageBox.Show 消息提示框显示到窗口最顶层
    Docker bash: ping: command not found 解决方法
    PLSQL F8执行单条SQL
  • 原文地址:https://www.cnblogs.com/kexiblog/p/10748354.html
Copyright © 2011-2022 走看看