mysql 擷取表有多少列

來源:互聯網
上載者:User

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='欄位'

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.