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
相关文档:
1.首先,设置数据库支持中文gb2312/gbk。
具体方法:
打开mySQL文件夹,修改my.ini配置文件。
[client]
port=3306
default-character-set=gb2312
以及
[mysqld]下的
default-character-set=gb2312
修改,保存,重启。若设为System服务,可以在控制面板-管理工具-服务中找到mySQL服务,重启。
2.保证Web ......
今天在写一条sql语句的时候,用的双引号,sql语句执行错误。记的同事问我mysql语句中的单引号和双引号有区别吗?回答是没有区别。
今天特地查了查,还是有点区别的。
mysql中的一段说明:
在mysql中,使用单引号和双引号俩种表达方法是一样的,尽管使用单引号的表达方法符合ANSI-SQL/92标准。
如果在字符串里有引号,则 ......
最初的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问 ......
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 ......
在Ubuntu9.10上使用sudo apt-get install mysql-server-5.0 安装了mysql,在外面访问不了mysql,但是在Ubuntu上访问是没有问题的。
于是开始查找原因:
3306端口是不是没有打开?
使用nestat命令查看3306端口状态:
~# netstat -an | grep 3306
tcp 0   ......