• MySQL判断库、表、列是否存在


    1.判断数据库是否存在

    select 1 from information_schema.schemata  where schema_name='数据库名';

    指定数据库名查询是否存在,若存在则返回1,若不存在测返回空。

    2.判断表是否存在

    select 1 from information_schema.tables where table_schema='数据库名' and table_name ='表名';

    指定表名查询是否存在,若存在则返回1,若不存在测返回空。(需指定在哪个数据库查询,若不指定则在整个服务上查询)

    3.判断列是否存在 

    select 1 from information_schema.columns  where table_schema='数据库名' and table_name='表名' and column_name ='列名';

    指定列名查询是否存在,若存在则返回1,若不存在测返回空。(需指定在哪个数据库查询,若不指定则在整个服务上查询)

  • 相关阅读:
    防御式编程
    Linux磁盘与文件系统管理
    更加抽象
    高质量的子程序
    Linux文件与目录管理
    抽象
    可以工作的类
    Linux的文件权限与目录配置
    条件、循环和其他语句
    软件构建中的设计
  • 原文地址:https://www.cnblogs.com/zys2019/p/16030597.html
Copyright © 2020-2023  润新知