华南俳烁实业有限公司

考試首頁 | 考試用書 | 培訓(xùn)課程 | 模擬考場 | 考試論壇  
全國  |             |          |          |          |          |         
  當(dāng)前位置:計算機等級 > 二級考試 > MySQL數(shù)據(jù)程序設(shè)計 > MySQL 輔導(dǎo) > 文章內(nèi)容
  

全國計算機等級考試二級MySQL教程(56)

中華IT學(xué)院   【 】  [ 2016年2月23日 ]

以下實例中假設(shè)數(shù)據(jù)庫 TUTORIALS 中的表 tcount_tbl 含有兩列 tutorial_author 和 tutorial_count, tutorial_count 中設(shè)置插入NULL值。

實例

嘗試以下實例:

root@host# mysql -u root -p password;
Enter password:*******
mysql> use TUTORIALS;
Database changed
mysql> create table tcount_tbl
    -> (
    -> tutorial_author varchar(40) NOT NULL,
    -> tutorial_count  INT
    -> );
Query OK, 0 rows affected (0.05 sec)
mysql> INSERT INTO tcount_tbl
    -> (tutorial_author, tutorial_count) values ('mahran', 20);
mysql> INSERT INTO tcount_tbl
    -> (tutorial_author, tutorial_count) values ('mahnaz', NULL);
mysql> INSERT INTO tcount_tbl
    -> (tutorial_author, tutorial_count) values ('Jen', NULL);
mysql> INSERT INTO tcount_tbl
    -> (tutorial_author, tutorial_count) values ('Gill', 20);

mysql> SELECT * from tcount_tbl;
+-----------------+----------------+
| tutorial_author | tutorial_count |
+-----------------+----------------+
| mahran          |             20 |
| mahnaz          |           NULL |
| Jen             |           NULL |
| Gill            |             20 |
+-----------------+----------------+
4 rows in set (0.00 sec)

mysql>

以下實例中你可以看到 = 和 != 運算符是不起作用的:

mysql> SELECT * FROM tcount_tbl WHERE tutorial_count = NULL;
Empty set (0.00 sec)
mysql> SELECT * FROM tcount_tbl WHERE tutorial_count != NULL;
Empty set (0.01 sec)

查找數(shù)據(jù)表中 tutorial_count 列是否為 NULL,必須使用IS NULL和IS NOT NULL,如下實例:

mysql> SELECT * FROM tcount_tbl 
    -> WHERE tutorial_count IS NULL;
+-----------------+----------------+
| tutorial_author | tutorial_count |
+-----------------+----------------+
| mahnaz          |           NULL |
| Jen             |           NULL |
+-----------------+----------------+
2 rows in set (0.00 sec)
mysql> SELECT * from tcount_tbl 
    -> WHERE tutorial_count IS NOT NULL;
+-----------------+----------------+
| tutorial_author | tutorial_count |
+-----------------+----------------+
| mahran          |             20 |
| Gill            |             20 |
+-----------------+----------------+
2 rows in set (0.00 sec)
分享到:
本文糾錯】【告訴好友】【打印此文】【返回頂部
將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動訪問考試網(wǎng) | 復(fù)制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
關(guān)于本站  網(wǎng)站聲明  廣告服務(wù)  聯(lián)系方式  站內(nèi)導(dǎo)航  考試論壇
Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved
安龙县| 合川市| 开封县| 阳泉市| 保定市| 靖西县| 简阳市| 贵阳市| 文成县| 洪江市| 福建省| 德安县| 米泉市| 商洛市| 山西省| 白沙| 榆林市| 乐亭县| 保德县| 宁波市| 综艺| 惠来县| 金门县| 同仁县| 平阴县| 商都县| 随州市| 房山区| 东至县| 监利县| 彰化县| 准格尔旗| 奈曼旗| 新乡县| 彭州市| 略阳县| 石楼县| 合作市| 鄂托克旗| 金华市| 静安区|