Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

SMO issue with default column values.

Offen
#175 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
38/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
csharp, sql
Bereich
databases

Rechercherichtung

Beginne damit, die CREATE TABLE- und ALTER TABLE-Fälle in SMO nachzustellen, und verfolge anschließend den SMO-Skriptpfad für Standardwerte, der das generierte SQL erzeugt. Vergleiche die Ausgabe mit der Datenbankdefinition und dem Verhalten von DacFx ScriptComparison; abgeschlossen ist die Aufgabe, wenn primitive Standardwerte wie 10 oder 0 konsistent und ohne redundante Klammern dargestellt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Greetings. To reproduce. . .

Create the following table:

CREATE TABLE DefaultTest (
    [FlagValue] INT DEFAULT 10
)

Then, generate the SMO script. You will get:

CREATE TABLE [dbo].[DefaultTest] (
    [FlagValue] INT DEFAULT ((10)) NULL
);

This is odd, why has the 10 become ((10))? Syntax wise, 10 is OK.
The same happens if you create the table without the default, then add it with:

ALTER TABLE DefaultTest ADD DEFAULT 10 FOR [FlagValue]

What's interesting, is that if you use Azure Data Studio to edit the ((10)) default value in the UI back to 10 (maybe the UI isn't using SMO?), the SQL it generates displays as:

CREATE TABLE [dbo].[DefaultTest] (
    [FlagValue] INT DEFAULT 10 NULL
);

. . . which instantly becomes ((10)) again when you apply the change to the database.

Now, the engine always stores the constraints definition wrapped with ( and ).
I contend there is a bug in SMO -- if the value within parenthesis is a primitive (string, integer, etc), then it doesn't need parenthesis.

Why is this a problem? Currently writing code to compare schemas against two databases, and having to parse weird output from DacFx's ScriptComparison, which is complaining that default values of (0) sometimes become ((0)). Now, I can write an AST parser using ScriptDom, but isn't this an SMO error?

Basically, it means that SMO isn't generating a technically identical representation of the table.

Thanks!

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus microsoft/sqlmanagementobjects

Alle Issues in microsoft/sqlmanagementobjects

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

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