Creating tables with inheritance I'm fairly new to SQL. I just wanted to create a database from scratch to learn. 

So I have a table called Addresses and I want to create two tables dependent on it that are Country and State, Im not sure what script to use for that.

Thanks in advance
I am not sure that I would consider this to be an issue of inheritance, and from the description, I would say that the Address table would depend on the other two tables instead of those two tables depending on the Address table.

But that minutia aside, I would recommend:


If you are only storing U.S. or maybe U.S. and Canada addresses, then you can do a "StateRegion" table. But in that case you don't really need a Country table.
If you are storing addresses from many countries, then you would want a Country table, but the StateRegion table is trickier as that varies greatly between countries. I will have to look to see if there is a standardized list for that.


If you want to attempt a "StateRegionProvince" table, check out this info on ISO 3166-2: http://en.wikipedia.org/wiki/ISO_3166-2

For countries, a Country table should be just the ISO list of countries. There is really no need for a separate ID field as the ISO country codes are an acceptable standard (hence the "S" in ISO :-). Just make CountryCode (I prefer the 2-character codes over the 3-character codes) a CHAR(2) NOT NULL.


Full ISO 3166-1 list of 2 character codes (most up to date): https://www.iso.org/obp/ui/#search
ISO list of 2 and 3 character codes: http://www.nationsonline.org/oneworld/country_code_list.htm
ISO 3166-1 and others list: http://www.geonames.org/countries/

If storing non-US/Canada-only addresses:


For "Zip Code", do a VARCHAR(15) field for "Postal Code" as there are various ways of doing those as well.


VARCHAR is fine as the only characters used are: 0-9, A-Z, [space], and [hyphen]
Postal Codes general info: http://en.wikipedia.org/wiki/Postal_code
Postal Code formats by country: http://en.wikipedia.org/wiki/List_of_postal_codes

Use NVARCHAR instead of VARCHAR for the Address, City, StateRegion, etc fields.



So, generally speaking:

CREATE TABLE County
(
   CountryCode CHAR(2) NOT NULL PRIMARY KEY,
   CountryName VARCHAR(100) NOT NULL
);

CREATE TABLE Address
(
   AddressID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
   UserID INT NOT NULL, -- FK to some User table
   AddressLine1 NVARCHAR(100) NOT NULL,
   AddressLine2 NVARCHAR(100) NULL,
   City NVARCHAR(100) NULL,
   StateProvince NVARCHAR(100) NOT NULL, -- or INT FK to StateProvince table?
   PostalCode NVARCHAR(20) NOT NULL,
   CountryCode CHAR(2) NOT NULL -- FK to Country table
)