During development, how do I select the mysql field length? for example, if I want to save a value of 0123456789 and select the int type, how much should I write for his "length/value? How can I calculate it? I found that this length/value can be 1, or I want to save the four characters "Your Name", which are varchar-type, what should I write about the length/value?
Reply to discussion (solution)
Only varchar and char fields need to be set. the width is calculated by character.
Note: a Chinese character is a character, but you need to set appropriate "Collation"
Only varchar and char fields need to be set. the width is calculated by character.
Note: a Chinese character is a character, but you need to set appropriate "Collation"
In this case, do you not need to set "length/value" (in phpmyadmin) for int type? can you give an example?
Good post, learning
Create table test_str_and_int (
Id int (10) not null auto_increment,
Str1 VARCHAR (3) not null,
Str2 VARCHAR (30) not null,
Test_int_1 TINYINT (1) not null default 1,
Test_int_2 SMALLINT (5) not null default 1,
PRIMARY key (id)
) ENGINE = MYISAM character set utf8;
Drop table test_str_and_int
DESC test_str_and_int
#-------------------------------------------------
Insert into test_str_and_int (str1, str2, test_int_1, test_int_2) values
('Testone ', 'testone', 1234567890,1234567890 ),
('Your name', 'Your Name', 1234567890,1234567890 ),
('Test Your Name', 'Test Your Name', 6789,6789 ),
('Your name is test', 'no matter how many characters are inserted into the SQL statement, it will be retained according to the length of the data field design', 19860502,19860503)
# --- Str1 --------------------------------------------------
SELECT * FROM test_str_and_int
Id str1 str2 int_1 int_2
1 tes testone 127 32767
2 Your name your name 127 32767
3 tes test your name 127 6789
4. no matter how many characters are inserted into the SQL statement, your name will be guaranteed to be 127 32767 characters in length based on the data field design.
# --- Conclusion -------- str1 and str2 are string-type, respectively designed as varchar (3). after varcvhar (30) is inserted into the database, retain 3 strings and 30 strings respectively.
# No matter how many characters are inserted into the SQL statement, the length is reserved based on the length of the data field design. you can design the length as needed. Generally, the string length is 20 or 32.
#-The same applies to the int type.
The length of char and varchar is one Chinese character. if you put a maximum of four characters, the length is set to 8, and then it cannot be put into five characters! As for the int length of 1, why can it be stored in 0123456789? I think it is this string of numbers. if you press 0, the database will automatically judge it as 0. you can set the length to 1 and save it as 123456789.
I have a website to contact me.