简体   繁体   中英

Data types for member's table?

What are the best data types to use for a members table and scores table on a mysql database?

I am creating a game in Java which connects to a hosted mysql database. I am unsure of which data types to use for each of the fields.

The fields I have are:

TABLE tMembers

ID INT(11)
firstName VARCHAR(255)
lastName VARCHAR(255)
email VARCHAR(255)
username VARCHAR(255)
password VARCHAR(255)

TABLE tScores

ID INT(11)
SCORE INT(11)
DATE DATETIME

I have heard a few things on SO and just form googling about the efficiency of using VARCHAR(80) for emails etc as emails cannot be longer than this, is this true?

For names, is varchar better than text (as a name cannot contain numbers or symbols, why not just use text ?)

Also, for the ID , should I use INT or INTEGER ?

Any help is more than appreciated.

I have heard a few things on SO and just form googling about the efficiency of using VARCHAR(80) for emails etc as emails cannot be longer than this, is this true?

yes, if you define a column as varchar(x), the length of the value you want to save into that column should smaller than x.

For names, is varchar better than text (as a name cannot contain numbers or symbols, why not just use text?)

varchar contains (Max length) less characters than text, depends on the mysql version you are using. eg 5.03+ varchar can contain 65535 characters. but for your requirement, a varchar type for "names" would be ok.

Also, for the ID, should I use INT or INTEGER?

as far as my understanding, the INT and INTEGER in mysql are the same. check http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html there you can see:

MySQL supports all standard SQL numeric data types. These types include the exact numeric data types (INTEGER, SMALLINT, DECIMAL, and NUMERIC), as well as the approximate numeric data types (FLOAT, REAL, and DOUBLE PRECISION). The keyword INT is a synonym for INTEGER , and the keywords DEC and FIXED are synonyms for DECIMAL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM