SQL Server Scripts to Store Countries, States and Cities in Database

Here, I provides the sql server database scripts which can be very useful in many application. When we create registration form or user information form, there is one basic thing is user's location including his/her country, state and city. So we need to provide the list of world's (most of) all countries, states and cities to the user, so they can choose their location from the list.

So, here is the script for the SQL Server database in which there are three mapped tables CountryMaster, StateMaster and CityMaster. These tables are related to each other using Primary key and foreign key in the tables. So we can easily map the data whenever its required. You can manually insert data to these tables later, if any new country, state or city found in the world.

Following are the Database Diagram of these tables with their relationship.


Download the attached .rar file which contains the scripts for these tables and then execute them in your database.
 
Note: Please first execute the CountryData.sql file then StateData.sql file and at last CityData.sql file, because of relationship of tables to each other.