0

I have a user table and I need to create a VIEW so a user can only see their own data/row.

How could I achieve this? I have been searching online on how to create views but I can't find anything useful/explains well!! Please help!!

tUser with user_id, name, address

2
  • What do you mean with view? Do you want to display everything in a table via php or something simmular? Commented May 9, 2015 at 21:23
  • @RobinR I need to do this in SQL Commented May 9, 2015 at 21:25

2 Answers 2

2

Only with having a field for user (id or name) you can make a view so that a user can see or manipulate only his/her data:

assuming your table is:

tbl (fld_1, usr,....) -- usr is for the the user who created the record

you can create your view as:

create view vw as
select * from tbl
where usr=current_user
Sign up to request clarification or add additional context in comments.

1 Comment

This answers your question. If you have some other question about stored procedures (which doesn't seem relevant), then you should ask that as another question.
0
Create View As VeiwDemo
Select * 
From Your_TableName
Where UserId=UserId

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.