一、实验目的
1、掌握MySQL数据库的创建、修改、删除和查看。
2、掌握表的创建、修改、删除和查看。
3、掌握表中记录的插入、修改和删除操作。
4、掌握完整性约束的创建和删除操作。
二、实验内容
使用SQL语句完成下列题目:
1、创建用户数据库petstore。(0.5分)
2、在数据库petstore中创建如下表,表结构如下:(3分)
用户表account
属性名称 | 含义 | 数据类型 | 为空性 | 备注 |
userid | 用户编号 | Char(6) | NOT NULL | 主键 |
fullname | 用户名 | Varchar(10) | NOT NULL | |
passward | 密码 | Varchar(20) | NOT NULL | |
sex | 性别 | Char(2) | NOT NULL | |
address | 住址 | Varchar(40) | NULL | |
| 邮箱 | Varchar(20) | NULL | |
phone | 电话 | Varchar(11) | NOT NULL |
商品表product
属性名称 | 含义 | 数据类型 | 为空性 | 备注 |
productid | 商品编号 | Char(10) | NOT NULL | 主键 |
catid | 类别编号 | Char(10) | NOT NULL | |
name | 商品名 | Varchar(30) | NOT NULL | |
descn | 商品介绍 | text | NULL | |
listprice | 市场价格 | Decimal(10,2) | NULL | |
unitcost | 成本价格 | Decimal(10,2) | NULL | |
qty | 数量 | Int(11) | NOT NULL |
订单表orders
属性名称 | 含义 | 数据类型 | 为空性 | 备注 |
orderid | 订单号 | Int(11) | NOT NULL | 主键,按订单生成顺序自动编号 |
userid | 用户编号 | Char(6) | NOT NULL | |
orderdate | 订单日期 | datetime | NOT NULL | 当前日期 |
totalprice | 订单总价 | Decimal(10,2) | NULL | |
status | 订单状态 | Tinyint(1) | NULL |
3、在petstore数据库的下列表中插入如下数据:(1.5分)
用户表account数据
userid | fullname | password | sex | address | | phone |
u0001 | 刘晓和 | 123456 | 男 | 广东深圳市 | liuxh@163 | 13512345678 |
商品表product数据
productid | catid | name | descn | listprice | unitcost | qty |
AV-CB-01 | 01 | 天使鱼 | 来自澳大利亚的海水鱼 | 10 | 10 | 100 |
订单表orders数据
orderid | userid | orderdate | totalprice | status |
20130411 | u0001 | 2013-04-11 15:07:34 | 200 | 0 |
4、新从澳大利亚购进一批天使鱼,数量为50条,进价为15元,按库存与新进商品的平均值调整商品的成本价格。该商品将以高出成本价格20%的市场价格卖出,调整商品的市场价格和数量。(2分)
5、订单号为20130411的订单已经发货,在订单表中将该订单的状态修改为1。(1分)
6、删除用户表中用户号为u0001的用户信息。(1分)
7、删除商品表中名称为“天使鱼”的商品信息。(1分)
三、实验代码及注释
1. create database petstore;2. create table account(userid char(6) not null primary key,fullname Varchar(10) NOT NULL,passward Varchar(20) NOT NULL,sex Char(2) NOT NULL,address Varchar(40) NULL,email Varchar(20) NULL,phone Varchar(11) NOT NULL);create table product(productid char(10) not null primary key,catid char(10) NOT NULL,name Varchar(30) NOT NULL,descn text NULL,listprice Decimal(10,2) NULL,unitcost Decimal(10,2) NULL,qty int(11) NOT NULL);create table orders(orderid Int(11) NOT NULL primary key auto_increment,userid Char(6) NOT NULL,orderdate datetime NOT NULL default now(),totalprice Decimal(10,2) NULL,status Tinyint(1) NULL);3. use petstore;insert into account values('u0001','刘晓和','123456','男','广东深圳市','liuxh@163','13512345678');insert into product values('AV-CB-01','01','天使鱼','来自澳大利亚的海水鱼','10.00','10.00',100);insert into orders values('20130411','u0001','2013-04-11 15:07:34','200.00',0);4.update product set unitcost= (unitcost*qty+50*15)/(qty+50) where name='天使鱼';update product set listprice= unitcost*1.2,qty=qty+50 where name='天使鱼';5. update orders set status=1 where orderid=20130411;6、delete from account where userid='u0001';7、delete from product where name='天使鱼';
四、运行结果截图
1、
5、
本文发布于:2024-01-30 04:51:07,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170656146919344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |