Skip to content

Fix: Add missing state_name and country_name columns to SQL Server CREATE TABLE schemas#1351

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-cities-create-table-columns
Draft

Fix: Add missing state_name and country_name columns to SQL Server CREATE TABLE schemas#1351
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-cities-create-table-columns

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

SQL Server CREATE TABLE statements for cities and states were missing columns already present in the exported JSON data.

What changed?

  • Added country_name NVARCHAR(255) NOT NULL after country_code in the states schema
  • Added state_name NVARCHAR(255) NOT NULL after state_code in the cities schema
  • Added country_name NVARCHAR(255) NOT NULL after country_code in the cities schema

ExportJson.php has always exported these fields (state_name, country_name for cities; country_name for states), so the INSERT statements—which derive columns directly from JSON keys—will populate them correctly without further changes.

Type of Change

  • 🐛 Bug/Data fix
  • ✨ New data (cities/states/countries)
  • 📝 Data update
  • 🔧 Infrastructure/Scripts
  • 📚 Documentation

Affected Locations

  • bin/Commands/ExportSqlServer.phpstates and cities schema definitions

Checklist

  • Edited JSON files in contributions/ directory
  • Omitted id field for new records (auto-assigned)
  • Verified data against reliable sources
  • Tested locally (optional)

Sources

Notes

The INSERT generation in generateSqlServerInsert() derives column names from array_keys($data[0]), so no changes are needed there — once the schema includes the columns, the JSON-sourced data will fill them automatically.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: SQL Server States and Cities Create Table Statement has missing Columns:</issue_title>
<issue_description>### Issue Type

Incorrect Data (wrong information)

Location (if applicable)

No response

What's wrong?

SQL Server Create Table Statements:

/****** Object: Table [world].[cities] Script Date: 26/02/2026 11:46:11 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [world].[cities](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[state_id] [int] NOT NULL,
[state_code] nvarchar NOT NULL,
[state_name] nvarchar NOT NULL,
[country_id] [int] NOT NULL,
[country_code] nchar NOT NULL,
[country_name] nvarchar NOT NULL,
[latitude] [decimal](10, 8) NOT NULL,
[longitude] [decimal](11, 8) NOT NULL,
[native] nvarchar NULL,
[type] nvarchar NULL,
[level] [int] NULL,
[parent_id] [int] NULL,
[population] [bigint] NULL,
[timezone] nvarchar NULL,
[translations] nvarchar NULL,
[wikiDataId] nvarchar NULL,
[created_at] datetime2 NOT NULL,
[updated_at] datetime2 NOT NULL,
[flag] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [world].[cities] ADD DEFAULT (sysdatetime()) FOR [created_at]
GO

ALTER TABLE [world].[cities] ADD DEFAULT (sysdatetime()) FOR [updated_at]
GO

ALTER TABLE [world].[cities] ADD DEFAULT ((1)) FOR [flag]
GO

ALTER TABLE [world].[cities] WITH CHECK ADD CONSTRAINT [FK_cities_countries] FOREIGN KEY([country_id])
REFERENCES [world].[countries] ([id])
GO

ALTER TABLE [world].[cities] CHECK CONSTRAINT [FK_cities_countries]
GO

ALTER TABLE [world].[cities] WITH CHECK ADD CONSTRAINT [FK_cities_states] FOREIGN KEY([state_id])
REFERENCES [world].[states] ([id])
GO

ALTER TABLE [world].[cities] CHECK CONSTRAINT [FK_cities_states]
GO

/States Table/

/****** Object: Table [world].[states] Script Date: 26/02/2026 11:47:12 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [world].[states](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[country_id] [int] NOT NULL,
[country_code] nchar NOT NULL,
[country_name] nvarchar NOT NULL,
[fips_code] nvarchar NULL,
[iso2] nvarchar NULL,
[iso3166_2] nvarchar NULL,
[type] nvarchar NULL,
[level] [int] NULL,
[parent_id] [int] NULL,
[native] nvarchar NULL,
[latitude] [decimal](10, 8) NULL,
[longitude] [decimal](11, 8) NULL,
[timezone] nvarchar NULL,
[translations] nvarchar NULL,
[wikiDataId] nvarchar NULL,
[population] [bigint] NULL,
[created_at] datetime2 NULL,
[updated_at] datetime2 NOT NULL,
[flag] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [world].[states] ADD DEFAULT (sysdatetime()) FOR [created_at]
GO

ALTER TABLE [world].[states] ADD DEFAULT (sysdatetime()) FOR [updated_at]
GO

ALTER TABLE [world].[states] ADD DEFAULT ((1)) FOR [flag]
GO

ALTER TABLE [world].[states] WITH CHECK ADD CONSTRAINT [FK_states_countries] FOREIGN KEY([country_id])
REFERENCES [world].[countries] ([id])
GO

ALTER TABLE [world].[states] CHECK CONSTRAINT [FK_states_countries]
GO

What should it be?

Updated Create Table Statements:

/****** Object: Table [world].[cities] Script Date: 26/02/2026 11:46:11 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [world].[cities](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[state_id] [int] NOT NULL,
[state_code] nvarchar NOT NULL,
[state_name] nvarchar NOT NULL,
[country_id] [int] NOT NULL,
[country_code] nchar NOT NULL,
[country_name] nvarchar NOT NULL,
[latitude] [decimal](10, 8) NOT NULL,
[longitude] [decimal](11, 8) NOT NULL,
[native] nvarchar NULL,
[type] nvarchar NULL,
[level] [int] NULL,
[parent_id] [int] NULL,
[population] [bigint] NULL,
[timezone] nvarchar NULL,
[translations] nvarchar NULL,
[wikiDataId] nvarchar NULL,
[created_at] datetime2 NOT NULL,
[updated_at] datetime2 NOT NULL,
[flag] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [world].[cities] ADD DEFAULT (sysdatetime()) FOR [created_at]
GO

ALTER TABLE [world].[cities] A...


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits February 28, 2026 08:41
…er export schema

Co-authored-by: dr5hn <6929121+dr5hn@users.noreply.github.com>
…EATE TABLE schemas

Co-authored-by: dr5hn <6929121+dr5hn@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing columns in cities create table statement Fix: Add missing state_name and country_name columns to SQL Server CREATE TABLE schemas Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SQL Server States and Cities Create Table Statement has missing Columns:

2 participants