赞
踩
其中:产品信息包括产品编号、产品名称、产品分类;
客户信息包括客户编号、客户名称、客户所在省、市、街道、邮编;
销售订单包括订单号、产品编号、客户编号、订单时间、登记时间和订单金额。
要求:提交编写的脚本,运行截图,上传实验报告文档。
CREATE TABLE `customer` (
`customer_number` int(11) NOT NULL COMMENT '客户编号',
`customer_name` varchar(50) DEFAULT NULL COMMENT '客户名称',
`customer_street_address` varchar(50) DEFAULT NULL COMMENT '客户住址',
`customer_zip_code` int(11) DEFAULT NULL COMMENT '邮编',
`customer_city` varchar(30) DEFAULT NULL COMMENT '所在城市',
`customer_state` varchar(30) DEFAULT NULL COMMENT '所在省份',
PRIMARY KEY (`customer_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE product(
product_code int NOT NULL COMMENT '产品编码',
product_name varchar(30) DEFAULT NULL COMMENT '产品名称',
product_category varchar (30) DEFAULT NULL COMMENT '产品类型',
PRIMARY KEY ( product_code )
)
CREATE TABLE sales_order (
order_number int NOT NULL COMMENT '订单号',
customer_number int DEFAULT NULL,
product_code int DEFAULT NULL,
order_date datetime DEFAULT NULL COMMENT '订单日期',
entry_date datetime DEFAULT NULL COMMENT '登记日期',
order_amount decimal (10,2) DEFAULT NULL COMMENT'销售金额',
PRIMARY KEY ( order_number )
)
BEGIN #Routine body goes here... set @start_time= unix_timestamp('2020-11-5'); set @end_time= unix_timestamp('2020-12-5'); set @i=1; while @i<=100 DO set @order_number = @i; set @customer_number = floor( 1+rand()*6); set @product_code = floor(1 + rand()* 2); set @order_date = from_unixtime(@start_time + rand()* (@end_time - @start_time)); set @amount := floor(1000 + rand()* 9000); insert into sales_order values (@order_number,@customer_number, @product_code,@order_date,@order_date,@amount); set @i=@i+1; end while; END
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。