Mysql键表/函数/存储过程

一:键表

drop table if exists `sub`.`customer_info`;

create table `sub`.`customer_info` (

	 `id` 		bigint(20)		not null 		AUTO_INCREMENT 	comment '编号'
	,`name` 	varchar(20) 	default null 					comment '姓名'
	,`address`  varchar(30)		default null  					comment '地址'
	,'price'	bigint(20) 		default null					comment '价格'
	,`num`		bigint(20) 		default null					comment '个数'
	,primary key (`id`)

	) ENGINE=INNODB AUTO_INCREMENT=1001 DEFAULT CHARSET=UTF8 COMMENT '客户明细表';

二:函数

--创造随机数
--创造from_num 到 to_num 的整数,包左不包右

delimiter $$

drop function if exists `rand_num` $$

create definer=`root`@`123` function `rand_num` (from_num int , to_num int) returns int(10)

	begin 

	declare i int default 0;

	set i = floor(from_num + rand() * (to_num - from_num + 1));

	return i ;

	end $$

	delimiter ;

三:存储过程

delimiter $$

drop procedure if exists `test_pro` $$

create definer=`root`@`123` procedure `test_pro` (data_date varchar(20) , sum int )

	begin 

	declare i int default 0;

	declare dd datetime default null ;

	repeat 

	set i = i + 1 ;

	set dd = date_add(data_date , -1) ; 

	insert into table customer_info (id,name,address,dt) values (i,'小明','深圳',dd) ;

		until i = sum 

		end repeat ;

		commit ; 

		end $$

		delimiter ;
		

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值