microsoft / microsoft/sqlmanagementobjects
SMO issue with default column values.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 143
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
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!
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
Start by reproducing the CREATE TABLE and ALTER TABLE cases in SMO, then trace the SMO default-value scripting path that produces the generated SQL. Compare the output with the database definition and the DacFx ScriptComparison behavior; done means primitive defaults such as 10 or 0 are represented consistently without redundant parentheses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100