when create a table, how i know which type and size i should use on the field. eg: what type should i use to time, email, phone, address…and so on.and which size i should give them. thank you.
This my approach, though it really depends on specific needs. So I am looking at it from a generic case.
- times, timestamp
- email, varchar(96) (its VERY unlikely to come across an email longer)
- phone, varchar(20) (enough to cover MOST cases but not something outrageous)
In most cases address is normally distributed across two or three columns such as; address_1 and address_2 that are something like varchar 128 though that may even be to much.
thank you,but if the field is a person’s name,Room number, and an article’s title or body? which type and size i should use?
firstname VARCHAR(99) NULL
lastname VARCHAR(99) NULL
roomnumber VARCHAR(9)
title VARCHAR(255)
body TEXT
interesting that you have shown the room number as varchar. Some places don’t use room numbers so yes, it has to be VARCHAR instead of INT but with the room name being so variable in length, I ususally set it to about 50. Arbitrary but, so far, sufficiently long.
Maybe I have something more to learn
bazz
good point… “the presidential suite” doesn’t have a room number
personally, I think there was a typo and you meant
roomnumber VARCHAR(99)
nope, i just thought room numbers like 1521A
firstname VARCHAR(99) NULL
lastname VARCHAR(99) NULL
title VARCHAR(255)
i think these size is too long, an article’s tilte maybe not have 255 characters? am i right?
depends on who is entering the article. But it’ll break your output, if you restrict it too much because part of the title wouldn’t be stored at all, if you make it too short.