Categories


Archives


Recent Posts


Categories


MySQL Address Fields

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Feeling as though it’s been some time since you posted, and with a desire to archive some useful text you always manage to loose on your hard drive, you decide to provide five MySQL ALTER statements that allow you to quickly add common address fields to any database table. Field types are defaults, and sometimes need to be changed depending on the project.

Dan Benjamin may reclaim his second-person voice as soon as he’s ready to use it again.

alter table [table-name] add address1 text not null;

alter table [table-name] add address2 text not null;

alter table [table-name] add city text not null;

alter table [table-name] add stateProvince
enum(
'--States--',
'AL','AK','AS','AZ','AR','CA','CO','CT','DE','DC','FM','FL','GA','GU','HI',
'ID','IL','IN','IA','KS','KY','LA','ME','MH','MD','MA','MI','MN','MS','MO',
'MT','NE','NV','NH','NJ','NM','NY','NC','ND','MP','OH','OK','OR','PW','PA',
'PR','RI','SC','SD','TN','TX','UT','VT','VI','VA','WA','WV','WI','WY',
'--Military State--','AE','AA','AP','--Provinces--','AB','BC','MB','NB','NL',
'NT','NS','NU','ON','PE','QC','SK','YT'
) 
not null;

alter table [table-name] add country 
enum('United States','Canada','Afghanistan','Albania','Algeria',
'American Samoa','Andorra','Anguilla','Antarctica',
'Antigua And Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan',
'Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize',
'Benin','Bermuda','Bhutan','Bolivia',
'Bosnia and Herzegovina','Botswana','BouvetIsland','Brazil',
'British Indian Ocean Territory','Brunei Darussalam','Bulgaria',
'Burkina Faso','Burundi','Cambodia','Cameroon','Cape Verde',
'Cayman Islands','Central African Republic','Chad','Chile','China',
'Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo','Congo,
 the Democratic Republic of the','Cook Islands','Costa Rica',
'Cote d\'Ivoire','Croatia','Cyprus',
'Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic',
'East Timor','Ecuador','Egypt','El Salvador','England',
'Equatorial Guinea','Eritrea','Espana','Estonia','Ethiopia','Falkland Islands',
'Faroe Islands','Fiji','Finland','France','French Guiana',
'French Polynesia',
'French Southern Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar',
'Great  Britain','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala',
'Guinea','Guinea-Bissau','Guyana','Haiti',
'Heard and Mc Donald Islands','Honduras',
'Hong Kong','Hungary','Iceland','India','Indonesia','Ireland','Israel','Italy',
'Jamaica','Japan','Jordan','Kazakhstan','Kenya','Kiribati',
'Korea (South)','Korea, Republic of','Kuwait','Kyrgyzstan',
'Lao People\'s Democratic Republic','Latvia','Lebanon','Lesotho','Liberia','Liechtenstein',
'Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia',
'Maldives','Mali','Malta',
'Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico',
'Micronesia, Federated States of','Moldova,
 Republic of','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Namibia',
'Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia',
'New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island',
'Northern Ireland',
'Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Panama',
'Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal',
'Puerto Rico','Qatar','Reunion','Romania','Russia',
'Russian Federation','Rwanda','Saint Kitts and Nevis','Saint Lucia',
'Saint Vincent and the Grenadines','Samoa (Independent)','San Marino',
'Sao Tome and Principe','Saudi Arabia','Scotland','Senegal','Seychelles',
'Sierra Leone','Singapore','Slovakia','Slovenia','Solomon Islands','Somalia',
'South Africa','South Georgia and the South Sandwich Islands',
'South Korea','Spain','Sri Lanka','St. Helena',
'St. Pierre and Miquelon','Suriname',
'Svalbard and Jan Mayen Islands','Swaziland','Sweden','Switzerland','Taiwan','Tajikistan',
'Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad',
'Trinidad and Tobago','Tunisia','Turkey','Turkmenistan',
'Turks and Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates',
'United Kingdom',
'United States Minor Outlying Islands','Uruguay','Uzbekistan','Vanuatu',
'Vatican City State (Holy See)','Venezuela','Viet Nam','Virgin Islands (British)',
'Virgin Islands (U.S.)','Wales','Wallis and Futuna Islands',
'Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe')
not null;

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 28th July 2005

email hidden; JavaScript is required