zoukankan      html  css  js  c++  java
  • mysql 获取表有多少列

    http://topic.csdn.net/u/20090109/15/39072242-c56c-4c83-81eb-7b1d940716d7.html

    【代码示例】
    [code=SQL]
    DELIMITER   $$
    DROP   FUNCTION   IF   EXISTS   `db_waasai`.`CheckIsObjectExist`$$
    CREATE   FUNCTION   `db_waasai`.`CheckIsObjectExist`(table_name   VARCHAR(50),colume_name   varchar(50))
    RETURNS   BOOLEAN
    BEGIN
    DECLARE   t_count   TINYINT   UNSIGNED;
    SELECT   count(0)   INTO   t_count   FROM   information_schema.COLUMNS   where   TABLE_NAME=table_name   &&   (isnull(colume_name)   ||   colume_name= ' '   ||   COLUMN_NAME=colume_name);
    RETURN   t_count> 0;
    END$$

    DROP   PROCEDURE   if   EXISTS   `db_waasai`.`sp_update_106_107`   $$
    CREATE   PROCEDURE   `db_waasai`.`sp_update_106_107`()
    BEGIN
    IF   NOT   CheckIsObjectExist( 'tbl_user_card ', ' ')   THEN
    CREATE   TABLE   `tbl_user_card`   (
    `u_id`   SMALLINT(6)   UNSIGNED   NOT   NULL   AUTO_INCREMENT,
    `u_status`   TINYINT(1)   UNSIGNED   DEFAULT   '0 ',
    `u_name`   VARCHAR(20)   NOT   NULL,
    PRIMARY   KEY     (`u_id`)
    )   ENGINE=MyISAM   DEFAULT   CHARSET=utf8   CHECKSUM=1   DELAY_KEY_WRITE=1   ROW_FORMAT=DYNAMIC;
    END   IF;

    IF   NOT   CheckIsObjectExist( 'tbl_user ', 'u_cards_num ')   THEN
    alter   table   `tbl_user`   add   column   `u_cards_num`   int   (12)   UNSIGNED     DEFAULT   '0 '   NULL     after   `u_age`;
    update   `tbl_user`   set   `u_cards_num`=1;
    END   IF;
    END$$
    DELIMITER   ;

    CALL   sp_update_106_107();
    DROP   PROCEDURE   IF   EXISTS   `lsgw`.`sp_update_106_107`;

    ***********************************************************************

    select * from information_schema.columns where table_schema='库' and table_name ='表' and column_name='字段'

  • 相关阅读:
    python 基础2
    ffmpeg安装和录制linux桌面图像
    Python TCP Socket 传输服务器资源信息(C/S)
    ubuntu下,hue3.7编译安装,设置中文语言
    Python 图片转字符画
    Python快速教程
    spark安装部署
    python基础之文件处理
    python之路之函数
    python习题
  • 原文地址:https://www.cnblogs.com/lingxzg/p/1848183.html
Copyright © 2011-2022 走看看