MySQL 中的 AUTO_INCREMENT 預設可以帶符號嗎?
是的,MySQL 中的 AUTO_INCREMENT 預設情況下將帶符號(正值和負值)。
我們先建立一個表 −
mysql> create table DemoTable -> ( -> MyNumber int AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.45 sec)
使用 insert 命令在表中插入一些記錄。在此,我們還為 AUTO_INCREMENT 列設定了負值 −
mysql> insert into DemoTable values() ; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(-100); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(-300); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.18 sec)
使用 select 語句顯示錶中的所有記錄 −
mysql> select *from DemoTable;
輸出
+----------+ | MyNumber | +----------+ | -300 | | -100 | | 1 | | 2 | +----------+ 4 rows in set (0.00 sec)
廣告