概述
MySQL 的触发器、存储过程、函数、视图实验
本实验完成如下结果:
0. test数据库,userinfo 用户信息表 和 userinfolog 用户信息日志表
1. 建立一个userinfo表新增记录时的触发器,将新增日志加入到userinfolog
2. 建立一个向userinfo表新增记录的存储过程
3. 根据userinfo表的出生日期字段,我们将建立一个简单算得年龄的自定义函数
4. 创建一个userinfo的视图,调用年龄函数
0.准备相关表
mysql> use test;
mysql> create table userinfo(userid int,username varchar(10),userbirthday date);
mysql> create table userinfolog(logtime datetime,loginfo varchar(100));
mysql> describe userinfo;
1.触发器
mysql> delimiter |
mysql> create trigger beforeinsertuserinfo
-> before insert on userinfo
-> for each row begin
-> insert into userinfolog values(now(),CONCAT(new.userid,new.username));
-> end;
-> |
mysql> delimiter ;
mysql> show triggers;
2.存储过程
mysql> delimiter //
mysql> create procedure spinsertuserinfo(puserid int,pusername varchar(10),puserbirthday date)
-> begin
-> insert into userinfo values(puserid,pusername,puserbirthday);
-> end;
-> //
mysql> show procedure status like 'spinsertuserinfo';
mysql> call spinsertuserinfo(1,'zhangsan',current_date);
&n
相关文档:
在日常的工作中,保护数据免受未授权用户的侵犯是系统管理员特别关心的问题。如果你目前用的是MySQL,就可以使用一些方便的功能来保护系统,来大大减少机密数据被未授权用户访问的风险。
企业最有价值的资产通常是其数据库中的客户或产品信息。因此,在这些企业中,数据库管理的一个重要部分就是保护这些数据免受外部攻击� ......
mysql 创建 数据库时指定编码很重要,很多开发者都使用了默认编码,但是我使用的经验来看,制定数据库的编码可以很大程度上避免倒入导出带来的乱码问题。
我们遵循的标准是,数据库,表,字段和页面或文本的编码要统一起来
很多mysql数据库工具(除了phpmyadmin,我偶尔用,功能强速度慢)都不支持创建时指定数据库编码, ......
最初的jbpm.hibernate.cfg.xml中,对MySQL的方言配置成了org.hibernate.dialect.MySQLDialect,发布流程的时候遇到下述错误:
Cannot delete or update a parent row: a foreign key constraint fails
Could not synchronize database state with session
将MySQL方言修改为org.hibernate.dialect.MySQLInnoDBDialect问 ......
Why you should ignore MySQL’s key cache hit ratio
http://www.mysqlperformanceblog.com/2010/02/28/why-you-should-ignore-mysqls-key-cache-hit-ratio/
不要相信mysql的key cache hit ratio:
key cache hit ratio = 1 - key_reads / key_read_requests
key_reads:从磁盘中读块的数量
key_read_request ......
package com.lovo.cq.shopping10_1.common;
import java.sql.*;
public class DbUtil {
private PreparedStatement pstmt = null;
private Connection con = null;
public DbUtil() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://l ......
最后
以上就是天真夕阳为你收集整理的mysql视图实验_MySQL 的触发器、存储过程、函数、视图实验的全部内容,希望文章能够帮你解决mysql视图实验_MySQL 的触发器、存储过程、函数、视图实验所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复