Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide a column from table in MS SQL Server

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

SSMS table defintion shows all columns

like image 504
Deepti Avatar asked May 16 '16 21:05

Deepti


People also ask

How do I hide a column in SQL?

In the Answerset, right-click the columns to hide and select Hide Columns. To show all columns, right-click in the Answerset and select Show All Columns.

How do I hide columns in a table?

To hide individual columns, open the table for which you are hiding a column, right-click the column, and click Hide from Client Tools. You can hide multiple columns at a time by holding down the Ctrl key or the Shift key.

How do I add a hidden column in SQL?

When temporal table is created, we need to defined start and end date time columns which can be hidden - not visible in SELECT * or INSERT without columns .


Video Answer


1 Answers

Late post but I think its worth to share

Earlier to SQLSERVER-2016 there was no any option to hide few columns from table when selecting *, however SQLSERVER-2016 come up with HIDDEN keyword by which you can now set columns hidden from Select * which you don't want to show and want only for some background process of your business logic.

The HIDDEN property is optional and will hide these columns from a standard SELECT statement for backward compatibility with our application and queries. You cannot apply the HIDDEN property to an existing column

.

you can alter existing table as well lets take an example of existing table

ALTER TABLE [dbo].[Account] ALTER COLUMN [StartDate] ADD HIDDEN;
ALTER TABLE [dbo].[Account] ALTER COLUMN [EndDate] ADD HIDDEN;

You can check this concept used more often in Temporal table

you can find more on this in below Temporal Table

like image 154
Ameya Deshpande Avatar answered Sep 27 '22 19:09

Ameya Deshpande