开发者

set min length to fields in mysql

开发者 https://www.devze.com 2023-01-31 19:23 出处:网络
hi am new to sql can anyone help me with it. I want to create a field example code date_type int auto increment with min size 9

hi am new to sql can anyone help me with it.

I want to create a field example code date_type int auto increment with min size 9 that is that number should be 000000001,000000002...000000010...开发者_如何学Python.


Use ZEROFILL. Here is an example:

CREATE TABLE zerofill_test (f1 INT(4) ZEROFILL,f2 INT(4));
INSERT INTO zerofill_test VALUES ( 1, 1 ), (10000, 10000);

Here f1 is defined with 'ZEROFILL' of 'int' type and f2 is simple int. When data is selected with SELECT command it shows you the desired result.

SELECT * FROM zerofill_test;
 +-------+-------+
 | h     | m     |
 +-------+-------+
 |  0001 |     1 |
 | 10000 | 10000 |
 +-------+-------+

For you purpose, the size of int field should be 9 i.e. `date_type int(9) ZEROFILL'

0

精彩评论

暂无评论...
验证码 换一张
取 消