MysQL中的两个谓词distinct和limit,它们的作用是什么?

MysQL中的两个谓词distinct和limit,它们的作用是什么?,第1张

MysQL中的两个谓词distinct和limit,它们的作用是LIMIT是MySQL内置函数,其作用是用于限制查询结果的条数。

LIMIT子句可以被用于强制 SELECT 语句返回指定的记录数。LIMIT 接受一个或两个数字参数。参数必须。

是一个整数常量。如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回。

记录行的最大数目。初始记录行的偏移量是 0(而不是 1): 为了与 PostgreSQL 兼容,MySQL 也支持句。

使用说明:

1、如果是用 MySQL + Apache,使用的又是 FreeBSD 网络 *** 作系统的话,安装时候你应按注意到FreeBSD的版本问题。

在 FreeBSD 的 3.0 以下版本来说,MySQL Source 内含的 MIT-pthread 运行是正常的,但在这版本以上,你必须使用 native threads,也就是加入一个 with-named-thread-libs=-lc_r 的选项。

2、如果在 COMPILE 过程中出了问题,请先检查你的 gcc版本是否在 2.81 版本以上,gmake 版本是否在3.75以上。

3、如果不是版本的问题,那可能是你的内存不足,请使用 ./configure--with-low-memory 来加入。

《PHP与mysql程序设计第四版》 498页视图章节

文档地址 网页链接也做了详细描述

摘抄自文档

The WITH CHECK OPTION clause can be given for an updatable view to prevent inserts to rows for which the WHERE clause in the select_statement is not true. It also prevents updates to rows for which the WHERE clause is true but the update would cause it to be not true (in other words, it prevents visible rows from being updated to nonvisible rows).

WITH CHECK OPTION 语句可以防止插入 可更新view 时候不满足view 的条件(比如我创建view 筛选的table_name 中age >5的数据,如果 我插入数据age小于等于5自然不行) ,他也可以用来防止 更新数据时本来是满足条件的要更新成不满足条件的情况(比如我创建view 的时候筛选条件是age >5 现在我要把其中一条本来是age >5 的数据更新成age =4 即小于5 就不ok 了 )    换句话说就是 防止本来可见的 变成不可见

In a WITH CHECK OPTION clause for an updatable view, the LOCAL and CASCADED keywords determine the scope of check testing when the view is defined in terms of another view. When neither keyword is given, the default is CASCADED. The LOCAL keyword restricts the CHECK OPTION only to the view being defined. CASCADED causes the checks for underlying views to be evaluated as well.

LOCAL 和 CASCADED 关键字主要用在一个view 来源于另外一个view的情况 ,默认CASCADED ,LOCAL 只的是只关心本view 创建时的条件 (比如view_a 包含的子句中内容 是 select * from view_b where age >5 那么我插入到view_a 中的时候 只关心 age>5 就可以了) 

如果 是CASCADED 表示还要关心 view_b 的条件( 比如

view_b 的条件是 select * from table_name where `salary` >3000  那么上面 在view_a创建数据的时候 age = 10 但是 salary 是2000 就无法插入)

下面是一个文档里面的例子 就不翻译了

Consider the definitions for the following table and set of views:

```

CREATE TABLE t1 (a INT)

CREATE VIEW v1 AS SELECT * FROM t1 WHERE a <2

WITH CHECK OPTION

CREATE VIEW v2 AS SELECT * FROM v1 WHERE a >0

WITH LOCAL CHECK OPTION

CREATE VIEW v3 AS SELECT * FROM v1 WHERE a >0

WITH CASCADED CHECK OPTION

```

Here the v2 and v3 views are defined in terms of another view, v1. v2 has a LOCAL check option, so inserts are tested only against the v2 check. v3 has a CASCADED check option, so inserts are tested not only against its own check, but against those of underlying views. The following statements illustrate these differences:

```

mysql>INSERT INTO v2 VALUES (2)

Query OK, 1 row affected (0.00 sec)

mysql>INSERT INTO v3 VALUES (2)

ERROR 1369 (HY000): CHECK OPTION failed 'test.v3'

```

这个编辑器不支持MD 所以只能这样了


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7315698.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存