MySQL 严格模式 sql_mode
虽然说我们尽量在写程序的时候控制插入到数据库的数据,而不要用数据库去判断数据的对错,但是有时候为了方便还是需要数据库自身的容错能力来帮助我们达到目的的。举例说明:
创建如下数据表
CREATE TABLE `book` (
`id` int(11) default NULL,
`num` int(11) unsigned default NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk
insert into bookvalues(1,0),(2,0)
执行update book set num='abc',竟然不报错,原因是没有启用严格模式。所以
先执行set sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION",
然后执行update book set num='abc',数据库就报错了
如果想一劳永逸,那就直接把数据库配置文件my.ini中的相关参数设置为
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
相关文档:
PL/SQL 不具备输入输出的能力
但是可以依靠环境来执行数值的输入输出给PL/SQL 块
SQLPLUS 环境用substitution variables 和 host(bind) variable 来传入数值给PL/SQL块
substitution variable: such as a preceding ampersand &a
host(bind) variable : such as a preceding colon :x
替 ......
一、安装
#
yum -y install mysql-server
二、配置
# vi /etc/my.cnf ← 编辑MySQL的配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility pack ......
SQL code动态sql语句基本语法
1 :普通SQL语句可以用Exec执行
eg: Select * from tableName
Exec('select * from tableName')
Exec sp_executesql N 'select * from tableName'
-- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
eg: declare @fname varchar(20)
......
MySQL语句优化的基本原则:
◆1、使用索引来更快地遍历表。
缺省情况下建立的索引是非群集索引,但有时它并不是最佳的。在非群集索引下,数据在物理上随机存放在数据页上。合理的索引设计要建立在对各种查询的分析和预测上。一般来说:
a.有大量重复值、且经常有范围查询( > ,< ,> =,& ......