• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

magal

Dúvida --> Tipo de dados ENUM no MySQL (para países)

2 mensagens neste tópico

Olá pessoal!

Alguém já precisou de usar um formulário com um grupo de selecções para o utilizador poder seleccionar o seu país no HTML?

					<select name="pais">
					<option value=""></option>
					<option value="US">United States</option>
					<option value="Canada">Canada</option>
					<option value="Germany">Germany</option>				
					<option value="Japan">Japan</option>
					<option value="UK">United Kingdom</option>
					<option value="Albania">Albania</option>
					<option value="AmerSamoa">American Samoa</option>
					<option value="Andorra">Andorra</option>
					<option value="Angola">Angola</option>
					<option value="Anguilla">Anguilla</option>
					<option value="Antarctica">Antarctica</option>
					<option value="Argentina">Argentina</option>				
					<option value="Armenia">Armenia</option>
					<option value="Aruba">Aruba</option>
					<option value="Australia">Australia</option>
					<option value="Austria">Austria</option>
					<option value="Azerbaijan">Azerbaijan</option>
					<option value="Bahamas">Bahamas</option>
					<option value="Bahrain">Bahrain</option>
					<option value="Banglad">Bangladesh</option>
					<option value="Barbados">Barbados</option>				
					<option value="Belarus">Belarus</option>
					<option value="Belgium">Belgium</option>
					<option value="Belize">Belize</option>
					<option value="Benin">Benin</option>
					<option value="Bermuda">Bermuda</option>
					<option value="Bhutan">Bhutan</option>
					<option value="Bolivia">Bolivia</option>
					<option value="BosniHerze">Bosnia Herzegowina</option>
					<option value="Botswana">Botswana</option>				
					<option value="BouvetIsl">Bouvet Island</option>
					<option value="Brazil">Brazil</option>
					<option value="BruneiDars">Brunei Darussalam</option>
					<option value="Bulgaria">Bulgaria</option>
					<option value="BurkinaFas">Burkina Faso</option>
					<option value="Cambodia">Cambodia</option>
					<option value="Cameroon">Cameroon</option>
					<option value="CapeVerde">Cape Verde</option>
					<option value="CaymanIsl">Cayman Islands</option>				
					<option value="Chad">Chad</option>
					<option value="Chile">Chile</option>
					<option value="China">China</option>
					<option value="ChristIsl">Christmas Island</option>
					<option value="CocosIsl">Cocos Islands</option>
					<option value="Colombia">Colombia</option>
					<option value="Comoros">Comoros</option>
					<option value="Congo">Congo</option>
					<option value="CongDemRep">Congo</option>				
					<option value="CookIsl">Cook Islands</option>
					<option value="CostaRica">Costa Rica</option>
					<option value="IvoryCoast">Cote d'Ivoire</option>
					<option value="Croatia">Croatia</option>
					<option value="Cuba">Cuba</option>
					<option value="Cyprus">Cyprus</option>
					<option value="CzechRep">Czech Republic</option>
					<option value="Denmark">Denmark</option>
					<option value="Djibouti">Djibouti</option>				
					<option value="Dominica">Dominica</option>
					<option value="DominRep">Dominican Redim</option>
					<option value="Ecuador">Ecuador</option>
					<option value="Egypt">Egypt</option>
					<option value="ElSalvador">El Salvador</option>
					<option value="EqGuinea">Equatorial Guinea</option>
					<option value="Estonia">Estonia</option>
					<option value="Ethiopia">Ethiopia</option>
					<option value="EU">European Union</option>				
					<option value="FalklndIsl">Falkland Islands</option>
					<option value="FaroeIsl">Faroe Islands</option>
					<option value="Fiji">Fiji</option>
					<option value="Finland">Finland</option>
					<option value="France">France</option>
					<option value="FrGuiana">French Guiana</option>
					<option value="FrPolyn">French Polynesia</option>
					<option value="Gabon">Gabon</option>
					<option value="Gambia">Gambia</option>				
					<option value="Georgia">Georgia</option>
					<option value="Ghana">Ghana</option>
					<option value="Gibraltar">Gibraltar</option>
					<option value="Greece">Greece</option>
					<option value="Greenland">Greenland</option>
					<option value="Grenada">Grenada</option>
					<option value="Guadeloupe">Guadeloupe</option>
					<option value="Guam">Guam</option>
					<option value="Guatemala">Guatemala</option>				
					<option value="Guinea">Guinea</option>
					<option value="GuinBissau">Guinea-Bissau</option>
					<option value="Guyana">Guyana</option>
					<option value="Haiti">Haiti</option>
					<option value="Honduras">Honduras</option>
					<option value="HongKong">Hong Kong</option>
					<option value="Hungary">Hungary</option>
					<option value="Iceland">Iceland</option>
					<option value="India">India</option>				
					<option value="Indonesia">Indonesia</option>
					<option value="Ireland">Ireland</option>
					<option value="Israel">Israel</option>
					<option value="Italy">Italy</option>
					<option value="Jamaica">Jamaica</option>
					<option value="Jordan">Jordan</option>
					<option value="Kazakhstan">Kazakhstan</option>
					<option value="Kenya">Kenya</option>
					<option value="Kiribati">Kiribati</option>				
					<option value="KorDemRep">Korea, North</option>
					<option value="KoreaRep">Korea, South</option>
					<option value="Kyrgyzstan">Kyrgyzstan</option>
					<option value="Lao">Lao</option>
					<option value="Latvia">Latvia</option>
					<option value="Lebanon">Lebanon</option>
					<option value="Lesotho">Lesotho</option>
					<option value="Liberia">Liberia</option>
					<option value="Liechten">Liechtenstein</option>				
					<option value="Lithuania">Lithuania</option>
					<option value="Luxemb">Luxembourg</option>
					<option value="Macau">Macau</option>
					<option value="Macedonia">Macedonia</option>
					<option value="Madagas">Madagascar</option>
					<option value="Malawi">Malawi</option>
					<option value="Malaysia">Malaysia</option>
					<option value="Maldives">Maldives</option>
					<option value="Mali">Mali</option>				
					<option value="Malta">Malta</option>
					<option value="Martinique">Martinique</option>
					<option value="Mauritania">Mauritania</option>
					<option value="Mauritius">Mauritius</option>
					<option value="Mexico">Mexico</option>
					<option value="Micrones">Micronesia</option>
					<option value="Moldova">Moldova</option>
					<option value="Monaco">Monaco</option>
					<option value="Mongolia">Mongolia</option>				
					<option value="Montser">Montserrat</option>
					<option value="Morocco">Morocco</option>
					<option value="Mozambiq">Mozambique</option>
					<option value="Myanmar">Myanmar</option>
					<option value="Namibia">Namibia</option>
					<option value="Nauru">Nauru</option>
					<option value="Nepal">Nepal</option>
					<option value="Nether">Netherlands</option>
					<option value="NewCaled">New Caledonia</option>				
					<option value="NewZea">New Zealand</option>
					<option value="Nicarag">Nicaragua</option>
					<option value="Niger">Niger</option>
					<option value="Nigeria">Nigeria</option>
					<option value="Niue">Niue</option>
					<option value="NorfolkIsl">Norfolk Island</option>
					<option value="Norway">Norway</option>
					<option value="Palau">Palau</option>
					<option value="Panama">Panama</option>				
					<option value="PapNewGuin">Papua New Guinea</option>
					<option value="Paraguay">Paraguay</option>
					<option value="Peru">Peru</option>
					<option value="Philippi">Philippines</option>
					<option value="Poland">Poland</option>				
					<option value="Portugal" selected="selected">Portugal</option>				
					<option value="PuertoRico">Puerto Rico</option>
					<option value="Qatar">Qatar</option>
					<option value="Romania">Romania</option>				
					<option value="RussianFed">Russian Federation</option>
					<option value="Rwanda">Rwanda</option>
					<option value="Samoa">Samoa</option>
					<option value="SanMarino">San Marino</option>
					<option value="Senegal">Senegal</option>
					<option value="Seychelles">Seychelles</option>
					<option value="SierraLeon">Sierra Leone</option>
					<option value="Singapore">Singapore</option>
					<option value="Slovakia">Slovakia</option>				
					<option value="Slovenia">Slovenia</option>
					<option value="SolomonIsl">Solomon Islands</option>
					<option value="SthAfrica">South Africa</option>
					<option value="Spain">Spain</option>
					<option value="SriLanka">Sri Lanka</option>
					<option value="StHelena">St. Helena</option>
					<option value="Suriname">Suriname</option>
					<option value="Swaziland">Swaziland</option>
					<option value="Sweden">Sweden</option>				
					<option value="Switzer">Switzerland</option>
					<option value="Taiwan">Taiwan</option>
					<option value="Tajikistan">Tajikistan</option>
					<option value="Tanzania">Tanzania</option>
					<option value="Thailand">Thailand</option>
					<option value="Togo">Togo</option>
					<option value="Tonga">Tonga</option>
					<option value="Tunisia">Tunisia</option>
					<option value="Turkey">Turkey</option>
					<option value="Turkmenist">Turkmenistan</option>
					<option value="Tuvalu">Tuvalu</option>
					<option value="Uganda">Uganda</option>
					<option value="Ukraine">Ukraine</option>
					<option value="UnArEmirat">United Arab Emirates</option>
					<option value="Uruguay">Uruguay</option>
					<option value="Uzbekistan">Uzbekistan</option>
					<option value="Vanuatu">Vanuatu</option>
					<option value="Venezuela">Venezuela</option>				
					<option value="Vietnam">Viet Nam</option>
					<option value="VirginIsls">Virgin Islands (British)</option>
					<option value="VirgIslUS">Virgin Islands (U.S.)</option>
					<option value="Yugoslav">Yugoslavia</option>
					<option value="Zambia">Zambia</option>
					<option value="Zimbabwe">Zimbabwe</option>			
				</select>

Pois bem, estou a usar o MySQL e PHP para construir um site e gostava de saber se algum de voces já usou o tipo de dados ENUM no MySQL para guardar então o país seleccionado pelo utilizador no form...

Alguém me pode dizer onde posso arranjar o código ENUM para os países?

É que é uma lista longa e pode demorar horas a fazer isso. Se alguém a tivesse agradecia.


Exemplo:

diaSemana ENUM ('Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado');

Obrigado! espero que tenham compreendido  :-[ Abraço

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Percebo perfeitamente a tua dúvida, mas acho que não vale a pena fazeres isso na base de dados.

È que o ENUM deve ser usado para pequenas listas de opções. Embora seja uma boa ideia ter o cuidado de ter consistência nos dados, com um ENUM tão grande ia provavelmente atrasar imenso os queries.

Recomendo que nao te preocupes com isso, e declares o campo como texto.

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora