dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Adjusting Views to Reduce Visibility of Data in MySQL

See how to make it so that tables with sensitive information are not viewable by all.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Let us consider a table representing employee data with a few columns, and, of course, their salary details as well.

It is not wise to expose this table to all querying entities since there is sensitive data that makes sharing the contents problematic.

In real time, there are VIEWS that can come in handy. You can create a VIEW with only the columns that need to be exposed and share that VIEW or permit read operation of that VIEW to users across various departments of the organization.



In MySQL, the syntax to create a VIEW is as below:

CREATE VIEW <VIEW_NAME> AS SELECT * FROM <TABLE_NAME>

The above syntax can be customized as needed. You must replace the * with the columns that you need to ensure that the sensitive data is not part of the view and thereby preventing it from being exposed. Of course, you need not permit anyone to access the <TABLE_NAME>, thereby ensuring privacy.

Example:

CREATE VIEW EMPLOYEE_DETAILS_VIEW AS SELECT EMP_ID, EMP_NAME, EMP_DEPT, EMP_DOB FROM EMPLOYEE_DETAILS

And yes, there are other conditional CREATE options that you can always explore.

 

Visit the DevX Tip Bank

 



   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date