NULLとDEFAULT値の動作確認


mysql> CREATE TABLE NULL_DEFAUL (
-> test1 INT NOT NULL,
-> test2 INT NULL,
-> test3 INT NOT NULL DEFAULT 123,
-> test4 INT NULL DEFAULT 456,
-> test5 CHAR(1) NOT NULL DEFAULT '0',
-> test6 VARCHAR(100) NOT NULL DEFAULT 'NO VALUES'
-> );
Query OK, 0 rows affected (0.00 sec)

mysql> desc NULL_DEFAUL;
+-------+--------------+------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+-----------+-------+
| test1 | int(11) | NO | | NULL | |
| test2 | int(11) | YES | | NULL | |
| test3 | int(11) | NO | | 123 | |
| test4 | int(11) | YES | | 456 | |
| test5 | char(1) | NO | | 0 | |
| test6 | varchar(100) | NO | | NO VALUES | |
+-------+--------------+------+-----+-----------+-------+
6 rows in set (0.01 sec)

mysql>

default

動作確認


mysql> desc NULL_DEFAUL;
+-------+--------------+------+-----+-----------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+-----------+-------+
| test1 | int(11) | NO | | NULL | |
| test2 | int(11) | YES | | NULL | |
| test3 | int(11) | NO | | 123 | |
| test4 | int(11) | YES | | 456 | |
| test5 | char(1) | NO | | 0 | |
| test6 | varchar(100) | NO | | NO VALUES | |
+-------+--------------+------+-----+-----------+-------+
6 rows in set (0.00 sec)

mysql> insert into NULL_DEFAUL(test1) values(1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from NULL_DEFAUL;
+-------+-------+-------+-------+-------+-----------+
| test1 | test2 | test3 | test4 | test5 | test6 |
+-------+-------+-------+-------+-------+-----------+
| 1 | NULL | 123 | 456 | 0 | NO VALUES |
+-------+-------+-------+-------+-------+-----------+
1 row in set (0.00 sec)

mysql>

default2

Comments are closed.

Post Navigation