microsoft / microsoft/sqlmanagementobjects

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

Offen
#214 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
C#
Sterne
143
Forks
28
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Verwenden Sie die ursprünglichen und generierten CREATE TABLE-Skripte im Bericht als Reproduktion, beginnend mit dem Generierungspfad Script as Create für temporale Azure SQL-Tabellen. Vergleichen Sie die generierte Ausgabe mit der Quelle und überprüfen Sie anschließend, dass das korrigierte Skript erfolgreich ausgeführt wird und dabei die Primary-Key- und Foreign-Key-Constraints erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, csharp, sql
Bereich
database, tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.