microsoft / microsoft/sqlmanagementobjects

[Bug]: Script as Create does not provide valid script

未关闭
#214 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug
主要语言
C#
星标
143
派生
28
PR 合并指标
30 天内没有已合并 PR

描述

Description

I cannot use Script as Create for tables in Azure SQL Database, as if I do I get errors as seen in the screenshot below.

Here is the original script:

CREATE TABLE transporter.CompanyProfile (
    CompanyProfileId int NOT NULL CONSTRAINT PK_transporter_CompanyProfile PRIMARY KEY IDENTITY(1,1),
    CompanyId int NOT NULL,
    CONSTRAINT FK_CompanyProfile_CompanyId 
    FOREIGN KEY (CompanyId) REFERENCES transporter.Company(CompanyId),
    ProfileId int NOT NULL,
    CONSTRAINT FK_CompanyProfile_ProfileId
    FOREIGN KEY (ProfileId) REFERENCES auth.Profile(ProfileId),
    Active bit NOT NULL,
    UpdatedDate DATETIME2 NOT NULL,
    UpdatedBy int NOT NULL,
    CONSTRAINT FK_CompanyProfile_UpdatedBy
    FOREIGN KEY (UpdatedBy) REFERENCES auth.Profile(ProfileId),
    ValidFrom DATETIME2 GENERATED ALWAYS AS ROW START NOT NULL,
    ValidTo DATETIME2 GENERATED ALWAYS AS ROW END NOT NULL,
    PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo)
)
WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = transporter.CompanyProfileHistory));

Here is the script generated using Script as Create:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [transporter].[CompanyProfile](
	[CompanyProfileId] [int] IDENTITY(1,1) NOT NULL,
	[CompanyId] [int] NOT NULL,
	[ProfileId] [int] NOT NULL,
	[Active] [bit] NOT NULL,
	[UpdatedDate] [datetime2](7) NOT NULL,
	[UpdatedBy] [int] NOT NULL,
	[ValidFrom] [datetime2](7) GENERATED ALWAYS AS ROW START NOT NULL,
	[ValidTo] [datetime2](7) GENERATED ALWAYS AS ROW END NOT NULL,
	PERIOD FOR SYSTEM_TIME ([ValidFrom], [ValidTo])
) ON [PRIMARY]
WITH
(
SYSTEM_VERSIONING = ON (HISTORY_TABLE = [transporter].[CompanyProfileHistory])
)
GO
ALTER TABLE [transporter].[CompanyProfile] ADD  CONSTRAINT [PK_transporter_CompanyProfile] PRIMARY KEY CLUSTERED 
(
	[CompanyProfileId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
ALTER TABLE [transporter].[CompanyProfile]  WITH CHECK ADD  CONSTRAINT [FK_CompanyProfile_CompanyId] FOREIGN KEY([CompanyId])
REFERENCES [transporter].[Company] ([CompanyId])
GO
ALTER TABLE [transporter].[CompanyProfile] CHECK CONSTRAINT [FK_CompanyProfile_CompanyId]
GO
ALTER TABLE [transporter].[CompanyProfile]  WITH CHECK ADD  CONSTRAINT [FK_CompanyProfile_ProfileId] FOREIGN KEY([ProfileId])
REFERENCES [auth].[Profile] ([ProfileId])
GO
ALTER TABLE [transporter].[CompanyProfile] CHECK CONSTRAINT [FK_CompanyProfile_ProfileId]
GO
ALTER TABLE [transporter].[CompanyProfile]  WITH CHECK ADD  CONSTRAINT [FK_CompanyProfile_UpdatedBy] FOREIGN KEY([UpdatedBy])
REFERENCES [auth].[Profile] ([ProfileId])
GO
ALTER TABLE [transporter].[CompanyProfile] CHECK CONSTRAINT [FK_CompanyProfile_UpdatedBy]
GO

Here are the errors when I run the generated script:
Image

Steps to Reproduce

Scripts are provided above.

Affected Area
  • Connection dialog (SQL Server | Azure browse/Fabric browse)
  • Query results panel
  • Query editor
  • Object Explorer
  • Table Designer
  • Schema Compare
  • Schema Designer
  • Local SQL Server Container provisioning
  • SQL database in Fabric provisioning
  • GitHub Copilot integration
  • Query Plan Visualizer
  • Other (please describe below)
If you selected "Other", please describe the affected area

Generated Scripts

Environment Information

Visual Studio Code: Version 1.104.1 (Universal)
Extension SQL Server (mssql):  v1.36.0
MacOS 15.6.1
Azure SQL

Confirmation
  • I have searched existing issues and couldn't find a match
  • I want to work on this issue

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用报告中的原始和生成的 CREATE TABLE 脚本作为复现材料,从 Azure SQL 时态表的 Script as Create 生成路径开始。将生成的输出与源进行比较,然后验证修正后的脚本能够成功执行,同时保留主键和外键约束。

由索引模型根据 Issue 内容生成。

评估

技术栈
azure, csharp, sql
领域
database, tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。