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'

  • 相关阅读:
    编译环境
    好看的函数图
    R语言学习
    python画图
    C++技巧
    DLL
    进程共享数据
    八数码问题
    document.getElementsByTagName()返回的是数组document.getElementsById()是dom内容
    使用Math.max,Math.min获取数组中的最值
  • 原文地址:https://www.cnblogs.com/kexiblog/p/10748354.html
Copyright © 2011-2022 走看看