T-SQL : duplication detected on extended property creation

When you are inserting extended properties on top of your SQL Server tables, you have to call the sp_addextendedproperty stored procedure.

Here is an example :

EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'frequency (in minutes)', @level0type = N'SCHEMA', @level0name = N'myschema', @level1type = N'TABLE', @level1name = N'mytable', @level2type = N'COLUMN', @level2name = N'frequence';

When analyzing the script, Sonar (my version is 9.3.0.51899) sees those multiple calls and treats them as code duplication.

Hello

I know it is a rather old topic, I just stumbled into it and was wondering if I understood correctly the problem.
From the documentation:

A piece of code is considered duplicated as soon as there are at least 100 duplicated tokens in a row spread across at least 10 lines of code

From a high-level perspective, the problem is that you have to call the same big sp_addextendedproperty stored procedures in multiple files/places, and there is no other way to avoid doing it.

In other words, duplication detection is correct, it is just that you cannot do without it. Did I understand correctly?

1 Like