Home > Database > Mysql Tutorial > 用SQL语句实现随机查询数据并不显示错误数据的方法

用SQL语句实现随机查询数据并不显示错误数据的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:57:21
Original
885 people have browsed it

用SQL语句实现随机查询数据并不显示错误数据的方法

问题:上级单位要来检查数据,我的服务器的数据库是SQL server 2000,上级单位要求我用SQL语句在服务器端随机查询50条数据出来。可是我的服务器里有些错误数据不希望他们看到,能不能有什么办法不让他们看到。
  SQL语句: select top 50 x from a_1 where c=xxxx

  语句就是要求这样写,然后他们来运行,怎么办,有什么办法可以在sql server上设置,然后使得这50条数据只在我找出的数据(比如正确的数据400)里随机查询出。尽量不要改动SQL语句。

  Peak Wong:

  可用视图:

  对方抽取时:

  select top 50 * from t_view --视图名

  order by newID()

  在生成视图时,把不显示出来的排除。视图在查询时,也就是一个表名的方式//只要对方不知道数据库表就行了。

  SQL code

   代码如下:
select top 10 ID,Name
  into T--生成测试表
  from sysobjects
  go
  create view Test--生成视图名
  as
  select * from T where ID>5
  go
  select top 2 * from test order by newID()--随机取两条


  说明:视图名,最好与表名比较相似就行了。create view Test--生成视图名

  with ENCRYPTION--加密一下,让对方看不到你的视图语句

  as

  select * from T where ID> 5

  go


本篇文章来源于 站长资讯网 原文链接:http://sqlserver.chinahtml.com/2007/119613367717217.shtml
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template