microsoft / microsoft/sqlmanagementobjects

SMO issue with default column values.

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

Dieses Issue hat noch niemand übernommen.

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

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!

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

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.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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