创建表,以及表之间的关系
use test;
create table person(
id smallint unsigned not null auto_increment,
name char(40) not null,
primary key(id));
create table shirt(
id smallint unsigned not null auto_increment,
style enum('t-shirt','polo','dress') not null,
color enum('red','blue','orange') not null,
owner smallint unsigned not null references person(id),
primary key(id));
创建视图
create view skirt_view as
select person.id as id,person.name as name,shirt.style as style,shirt.color as color from person,shirt
where person.id=shirt.owner;
创建用户
grant all privileges on *.* to 'money2'@'%' identified by 'panjun2' with grant option;
grant all privileges on *.* to 'money2'@'localhost' identified by 'panjun2' with grant option;
创建存储过程以及函数
格式:
CREATE PROCEDURE 过程名 ([过程参数[,...]])
[特性 ...] 过程体
CREATE FUNCTION 函数名 ([函数参数[,...]])
RETURNS 返回类型
[特性 ...] 函数体
过程参数:
[ IN | OUT | INOUT ] 参数名 参数类型
函数参数:
参数名 参数类型
返回类型:
有效的MySQL数据类型即可
过程体/函数体:格式如下:
BEGIN
有效的SQL语句
END
在开发过程中有几点要注意:
1、存储过程注释