【问题标题】:How to create a VIEW in SQL如何在 SQL 中创建视图
【发布时间】:2015-05-09 21:18:17
【问题描述】:

我有一个用户表,我需要创建一个视图,以便用户只能看到他们自己的数据/行。

我怎样才能做到这一点?我一直在网上搜索如何创建视图,但找不到任何有用/解释得很好的东西!!请帮忙!!

tUseruser_id, name, address

【问题讨论】:

  • 视图是什么意思?您想通过 php 或类似的方式在表格中显示所有内容吗?
  • @RobinR 我需要在 SQL 中执行此操作

标签: sql sql-server sql-server-2008 view


【解决方案1】:

只有拥有用户字段(id 或名称),您才能创建视图,以便用户只能查看或操作他/她的数据:

假设你的桌子是:

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

您可以将视图创建为:

create view vw as
select * from tbl
where usr=current_user

【讨论】:

  • 这回答了你的问题。如果您还有其他关于存储过程的问题(似乎不相关),那么您应该将其作为 another 问题提出。
【解决方案2】:
Create View As VeiwDemo
Select * 
From Your_TableName
Where UserId=UserId

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多