Guest User

Untitled

a guest
Apr 27th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. mysql> create table foo (id integer primary key auto_increment not null, port integer uniqu
  2. e null);
  3. Query OK, 0 rows affected (0.00 sec)
  4.  
  5. mysql> insert into foo (port) values (200);
  6. Query OK, 1 row affected (0.00 sec)
  7.  
  8. mysql> insert into foo (port) values (null);
  9. Query OK, 1 row affected (0.00 sec)
  10.  
  11. mysql> insert into foo (port) values (null);
  12. Query OK, 1 row affected (0.00 sec)
  13.  
  14. mysql> select * from foo;
  15. +----+------+
  16. | id | port |
  17. +----+------+
  18. | 1 | 200 |
  19. | 2 | NULL |
  20. | 3 | NULL |
  21. +----+------+
  22. 3 rows in set (0.00 sec)
  23.  
  24. mysql> ^DBye
  25.  
  26. ----------
  27.  
  28. CREATE TABLE `ammon`.`nulltest` (
  29. `oid` INT NOT NULL AUTO_INCREMENT ,
  30. `host` VARCHAR( 64 ) NOT NULL ,
  31. `port` INT NULL ,
  32. PRIMARY KEY ( `host` , `port` , `oid` )
  33. )
  34.  
  35. mysql> insert into nulltest (host,port) values ('foo',100);
  36. Query OK, 1 row affected (0.00 sec)
  37.  
  38. mysql> insert into nulltest (host,port) values ('foo',101);
  39. Query OK, 1 row affected (0.00 sec)
  40.  
  41. mysql> insert into nulltest (host,port) values ('foo',null);
  42. ERROR 1048 (23000): Column 'port' cannot be null
  43.  
  44. mysql> describe nulltest;
  45. +-------+-------------+------+-----+---------+----------------+
  46. | Field | Type | Null | Key | Default | Extra |
  47. +-------+-------------+------+-----+---------+----------------+
  48. | oid | int(11) | NO | PRI | NULL | auto_increment |
  49. | host | varchar(64) | NO | PRI | NULL | |
  50. | port | int(11) | NO | PRI | 0 | |
  51. +-------+-------------+------+-----+---------+----------------+
  52. 3 rows in set (0.00 sec)
  53.  
  54. ----------
  55.  
  56. CREATE TABLE `ammon`.`nulltest` (
  57. `oid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  58. `host` VARCHAR( 64 ) NOT NULL ,
  59. `port` INT NULL ,
  60. UNIQUE (
  61. `host` ,
  62. `port`
  63. )
  64. )
  65.  
  66. mysql> insert into nulltest (host,port) values ('foo',100);
  67. Query OK, 1 row affected (0.00 sec)
  68.  
  69. mysql> insert into nulltest (host,port) values ('foo',101);
  70. Query OK, 1 row affected (0.00 sec)
  71.  
  72. mysql> insert into nulltest (host,port) values ('foo',null);
  73. Query OK, 1 row affected (0.00 sec)
  74.  
  75. mysql> insert into nulltest (host,port) values ('foo',null);
  76. Query OK, 1 row affected (0.00 sec)
  77.  
  78. mysql> select * from nulltest;
  79. +-----+------+------+
  80. | oid | host | port |
  81. +-----+------+------+
  82. | 1 | foo | 100 |
  83. | 2 | foo | 101 |
  84. | 3 | foo | NULL |
  85. | 4 | foo | NULL |
  86. +-----+------+------+
  87. 4 rows in set (0.00 sec)
  88.  
  89. mysql> describe nulltest;
  90. +-------+-------------+------+-----+---------+----------------+
  91. | Field | Type | Null | Key | Default | Extra |
  92. +-------+-------------+------+-----+---------+----------------+
  93. | oid | int(11) | NO | PRI | NULL | auto_increment |
  94. | host | varchar(64) | NO | MUL | NULL | |
  95. | port | int(11) | YES | | NULL | |
  96. +-------+-------------+------+-----+---------+----------------+
  97. 3 rows in set (0.00 sec)
Add Comment
Please, Sign In to add comment