mysql学习笔记(二)

15索引

空间索引是对空间数据类型的字段建立的索引。

mysql的空间数据类型:geometry、point、linestring、polygon

创建空间索引的列,必须将其声明为not null

mysql 使用spatial关键字进行扩展

mysql中只有myisam存储引擎支持空间索引。

全文索引类型为fulltext ,在定义索引的列上支持值得全文查找,允许在这些索引列中插入重复值和空值。可以在char、varchar、text类型的列上创建。mysql中只有myisam存储引擎支持全文索引。

union 、fulltext、spatial 唯一索引、全文索引、空间索引。

mysql>explain select * from table where a=10 \G(查看表的索引情况)

在已经建好的表上建索引

alter table tablename add (union\fulltext\spatial) index indexname (字段名(索引长度))

create(union\fulltext\spatial) index indexname on tablename(字段名)

删除索引

alter table tablename drop index indexname

drop index indexname on tablename

16存储过程

创建存储过程:create procedure sp_name

调用存储过程:call

创建函数:create function

游标:

declare cursor_name cursor for select_name

open cursor_name

fetch cursor_name into var_name

close cursor_name

//loop leave

add_name:loop

set @count =@count+1 ;

if @count=50 then leave add_name ;//leave 跳出循环

end loop add_name;

 

//loop iterate

create procedure doiterate()

begin

declare p1 int defaut 0;

my_loop :loop

set p1=p1+1;

if p1<10 then iterate my_loop; //重新执行 p1=p1+1

elseif p1>20 then leave my_loop;

end if ;

select 'p1 is between 10 and 20';

end loop my_loop;

end

 

//repeat

declare id int default 0;

repeat //重复执行循环,直到满足条件后退出

set id =id+1;

until id>=10

end repeat;

 

//while

declare i int default 0;

while i<10 do //重复执行循环过程

end while;

 

查看存储过程:

mysql> show procedure status like 'c%' \G

 

参看存储\函数的定义

mysql>show create procedure\ founction sp_name \G

 

从information_schema.Routines表中查看存储过程和函数的信息

select * from information_schema.Routines

where routine_name='sp_name';

 

修改存储过程\函数

alter procedure\function sp_name

 

删除存储过程\函数

drop procedure\function sp_name

 

17视图

创建视图

create view view_t (a,b,c,d) as select a,b,c,d from t;

查看视图的基本信息

mysql>descibe view_t;

 

查看视图的基本信息

mysql>show table status like '视图名' \G

 

查看创建视图的信息

mysql>show create view vie_t \G

 

在view表中查看视图的信息

mysql>select * from information.schema.views \G

 

使用create or replace view

mysql>create or replace view view_t as select * from t;

 

使用alter修改视图

mysql>alter view view_t as select * from t;

 

视图可以insert、update、delete,会改动视图对应的表中的数据

 

删除视图

mysql>drop view if exists view_t;

 

18触发器

create trigger trigger_name before\after insert\update\delete

on table_name for each row

begin

语句执行列表

end

 

查看触发器信息

mysql>show trigger \G;

 

在trigger表中查看触发器信息

mysql>selcet * from information_schema.trigger \G;

 

删除触发器

mysql>drop trigger trigger_name;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值