microsoft / microsoft/sqlmanagementobjects

SMO issue with default column values.

未关闭
#175 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
C#
星标
143
派生
28
PR 合并指标
30 天内没有已合并 PR

描述

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!

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先在 SMO 中重现 CREATE TABLE 和 ALTER TABLE 的情况,然后跟踪生成 SQL 的 SMO 默认值脚本路径。将输出与数据库定义以及 DacFx ScriptComparison 的行为进行比较;当 10 或 0 等原始默认值能够以一致的方式表示且没有多余的括号时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, sql
领域
databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。