My requirement is to grant only few columns access to a user and still have the ability to run select * without error. Right now I am getting error -
select command denied to user ''@' ' for column 'id' in table
Reason: I have a table with 100 columns, out of which only two need to be barred from access. In such a scenario, a user has to write select 98 columns from table
instead of a simple select * from table
.
Is there a way we could make it work?
I don't have experience as a DBA for MySQL, but here is what I would do in MS SQL Server:
Added bonus:
SELECT *
is a generally a bad idea. Prohibit anyone from running SELECT *
on the table by adding an errant computed column to the table. In MS SQL Server, this would look like this:
CREATE TABLE [dbo].[NoSelectStar](
[id] [int] IDENTITY(1,1) NOT NULL,
[a] [varchar](7) NULL,
[NoSelectStar] AS ((1)/(0)), -- This is the one that deliberately causes problems.
CONSTRAINT [pkNoSelectStar] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
insert NoSelectStar
values ('a'), ('b'), ('c')
-- This will work
select a
from NoSelectStar
-- This will fail
select *
from NoSelectStar