BUG: Incorrect column permissions shown/scripted (10.5&10.4)
ivanjh
Posts: 12
Execute (I used SQL x64 Version: 11.0.3000.0):
CREATE TABLE [ColTest]([A] [int], [int], [C] [int], [D] [int])
GRANT UPDATE ([C]) ON [dbo].[ColTest] TO [public]
ALTER TABLE [ColTest] DROP COLUMN
--Run export/compare
--Shows: GRANT UPDATE ([D]) ON [dbo].[ColTest] TO [public]
--Expected: GRANT UPDATE ([C]) ON [dbo].[ColTest] TO [public]
When using compare - it'll continually show a difference that doesn't exist.
When creating a scripts folder - it'll script out the wrong permissions (doh!)
I'm guessing there's an assumption that sys.columns.column_id is always sequential. Nope, deletes leave holes.
Actively causing some confusion here... a fix would be nice.
CREATE TABLE [ColTest]([A] [int], [int], [C] [int], [D] [int])
GRANT UPDATE ([C]) ON [dbo].[ColTest] TO [public]
ALTER TABLE [ColTest] DROP COLUMN
--Run export/compare
--Shows: GRANT UPDATE ([D]) ON [dbo].[ColTest] TO [public]
--Expected: GRANT UPDATE ([C]) ON [dbo].[ColTest] TO [public]
When using compare - it'll continually show a difference that doesn't exist.
When creating a scripts folder - it'll script out the wrong permissions (doh!)
I'm guessing there's an assumption that sys.columns.column_id is always sequential. Nope, deletes leave holes.
Actively causing some confusion here... a fix would be nice.
Comments
Run this on SQL Server:
SQL Compare scripts this: No mention of columns in the update permissions. Possibly because SQL Compare is doing this cumulatively, because if I deny to public on A I do get a script denying update to A from SQL Compare.
Can you please provide a working script that reproduces the problem?
Yes, your example exposed another facet of the same core issue.
You've granted on the LAST column (C), and then deleted an earlier one (B).
Resulting in the GRANT being for the column after C - which doesn't exist... so it gives a table wide GRANT (very, very wrong).
For my original example, the grant is on the SECOND LAST column.
I've granted on the SECOND LAST column (C), and then deleted an earlier one (B).
Resulting in the GRANT being scripted for the column after C - which is D (also very wrong).
SQL Compare generates this:
Notice the incorrect columns in the grants (DFG when it should have been CEF).
It appears the column names for the grants are being determined using sys.columns.column_id as a positional index into the column list, instead of matching on column_id.