dr5hn / countries-states-cities-database

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities
https://dr5hn.github.io/countries-states-cities-database/
Open Data Commons Open Database License v1.0
6.82k stars 2.45k forks source link

Support for Microsoft SQL Server? #501

Open JamoCA opened 1 year ago

JamoCA commented 1 year ago

Are there any plans to generate SQL files to support importing the data into Microsoft SQL Server?

I compared the SQL data with the CSV file and would prefer to use the SQL files since they contain more complete data.

If not, is there a MSSQL schema that can be provided so that tables with the best datatypes + length can be created prior to bulk importing the CSV data? (The column names for SQL and CSV aren't the same.)

Thanks!

SilverBull commented 1 year ago

You just have to convert it with the correct syntax / type and collation you want.

CREATE TABLE test.dbo.countries (
    id int IDENTITY(0, 1) NOT NULL,
    name varchar(100) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NOT NULL,
    iso3 char(3) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    numeric_code char(3) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    iso2 char(2) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    phonecode varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    capital varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    currency varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    currency_name varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    currency_symbol varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    tld varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    native varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    region varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    subregion varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    timezones varchar(MAX) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    translations varchar(MAX) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    latitude decimal(10, 8) DEFAULT NULL,
    longitude decimal(11, 8) DEFAULT NULL,
    emoji varchar(191) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    emojiU varchar(191) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL,
    created_at datetime DEFAULT getdate() NULL,
    updated_at datetime DEFAULT getdate() NOT NULL,
    flag tinyint DEFAULT 1 NOT NULL,
    wikiDataId varchar(255) COLLATE Latin1_General_100_CI_AS_SC_UTF8 NULL DEFAULT NULL,
    CONSTRAINT countries_PK PRIMARY KEY (id)
);
JamoCA commented 1 year ago

Thanks. It's primarily the same for table creation, but the rest of the SQL (after table creation) that performs the inserting doesn't work with MSSQL.

If these instructions were intended to be used with the CSV file, the CSV file doesn't contain translations, flag or wikiDataId columns and would be NULL. I guess I could consume the JSON file with an application and manually update the countries with the 3 missing columns. It's not the most performant, but is it the only options for MSSQL users? (Thanks.)

SilverBull commented 1 year ago

Well I eventually created the tables on a mysql and then copied the data to the mssql db after creating the tables by converting the create statement. I guess in the end it just comes down to the most practical method for everyone