microsoft / microsoft/sqlmanagementobjects
[Bug]: Script as Create does not provide valid script
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 143
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
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:
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the original and generated CREATE TABLE scripts in the report as the reproduction, starting with the Script as Create generation path for Azure SQL temporal tables. Compare the generated output with the source, then verify the corrected script executes successfully while preserving the primary key and foreign key constraints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, sql
- Domain
- database, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100