哪种MySQL数据类型可用于存储负数?
您可以在MySQL中使用TINYINT数据类型存储负数。以下是语法-
CREATE TABLE yourTableName ( yourColumnName TINYINT . . . . N );
让我们首先创建一个表,该表的列设置为TINYINT类型-
mysql> create table DemoTable ( Number tinyint );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(-10); mysql> insert into DemoTable values(-128); mysql> insert into DemoTable values(128); ERROR 1264 (22003): Out of range value for column 'Number' at row 1 mysql> insert into DemoTable values(127); mysql> insert into DemoTable values(-1); mysql> insert into DemoTable values(14);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------+ | Number | +--------+ | -10 | | -128 | | 127 | | -1 | | 14 | +--------+ 5 rows in set (0.00 sec)