Skip to content

fix(sqlserver): preserve IDENTITY columns when copying table (#1691)#1918

Open
HandSonic wants to merge 1 commit into
OtterMind:mainfrom
HandSonic:fix/1691-copy-table-identity
Open

fix(sqlserver): preserve IDENTITY columns when copying table (#1691)#1918
HandSonic wants to merge 1 commit into
OtterMind:mainfrom
HandSonic:fix/1691-copy-table-identity

Conversation

@HandSonic

Copy link
Copy Markdown
Contributor

Use tableDDL() to generate proper CREATE TABLE DDL that preserves IDENTITY, computed columns, constraints, and indexes.

For data copying, wrap INSERT INTO...SELECT with SET IDENTITY_INSERT ON/OFF to allow explicit values in identity columns.

The previous SELECT * INTO approach silently dropped IDENTITY properties.

Fixes #1691

…nd#1691)

Use Chat2DBContext.getDbMetaData().tableDDL() to generate proper CREATE TABLE
DDL that preserves IDENTITY, computed columns, constraints, indexes, etc.

For data copying, wrap INSERT INTO...SELECT with SET IDENTITY_INSERT ON/OFF
to allow explicit values in identity columns.

The previous SELECT * INTO approach silently dropped IDENTITY properties.
@HandSonic HandSonic closed this Jul 21, 2026
@HandSonic HandSonic reopened this Jul 21, 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: 复制表结构的时候,把id自增的约束没有复制到新表

1 participant