microsoft / microsoft/sqlmanagementobjects

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

Ouverte
#214 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
C#
Étoiles
143
Forks
28
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Utilisez les scripts CREATE TABLE d’origine et généré dans le rapport comme reproduction, en commençant par le chemin de génération Script as Create pour les tables temporelles Azure SQL. Comparez la sortie générée avec la source, puis vérifiez que le script corrigé s’exécute correctement tout en conservant les contraintes de clé primaire et de clé étrangère.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
azure, csharp, sql
Domaine
database, tooling
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.