microsoft / microsoft/sqlmanagementobjects

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

Aperta
#214 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
C#
Stelle
143
Fork
28
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Utilizzare gli script CREATE TABLE originale e generato nel report come riproduzione, iniziando dal percorso di generazione Script as Create per le tabelle temporali di Azure SQL. Confrontare l’output generato con l’origine, quindi verificare che lo script corretto venga eseguito correttamente mantenendo i vincoli di chiave primaria e chiave esterna.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
azure, csharp, sql
Ambito
database, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.