Can anyone please share the steps to hide the particular column from the table in SQL Server 2012 as I don't want to delete that column
By hide I mean that whenever I use the select query against that particular table it should never show me that column.
Is it possible? I need to make the column as hidden irrespective of any user login and whatever query i use
3rd party edit
Based on the comment But the problem is whenever i open the table in sql i dont want to see that particular column
i assume that the question is:
- How can i configure ssms so that opening a table definition inside sql management studio to only show the columns the connected user has select right to?
The screenshot below shows all columns of the table Employee despite the fact that the login StackoverIntern
has no select rights to the columns SSN, Salary
Earlier to SQLSERVER-2016 there was no any option to hide few columns from table when
selecting *
, howeverSQLSERVER-2016
come up withHIDDEN
keyword by which you can now set columns hidden fromSelect *
which you don't want to show and want only for some background process of your business logic..
you can alter existing table as well lets take an example of existing table
You can check this concept used more often in
Temporal table
you can find more on this in below Temporal Table
You can use column level permissions so that targeted users cannot select on that column. However, this will not "hide" the column in the case of doing a
SELECT *
orSELECT SpecialColumn
. Instead, it will fail the query, resulting in an error.An alternative to allow easier queries, you can make a View that does not include this column:
Then only grant SELECT permissions to the View, rather than the table, for certain users. However, this is still problematic for an application, which now has to know whether it should select from the Table or the View.
When it comes down to it, column level permissions are kind of an unnatural thing to do in a database.
If you do not want the column to show, then you should not include it in you select statement. It is also more efficient to not use an
asterisk (*)
in your select statement.See this post for more info in the performance issue: Performance issue in using SELECT *?