#1.创建Book表,字段如下
/*bid 整型,要求主键
bname 字符型,要求设置唯一键,并非空
price 浮点型,要求有默认值 10
btypeId类型编号,要求引用bookType表的id
已知bookType表(不用创建),字段如下:
id
name
*/
CREATE TABLE Book(
bid INT PRIMARY KEY,
bname VARCHAR(20) UNIQUE NOT NULL,
price FLOAT DEFAULT 10,
btypeId INT
FOREIGN KEY(btypeId)
);
#2.开启事务
/*向表中插入1行数据,并结束*/
SET autocommit=0;
INSERT INTO book(bid,bname,btypeId)
VALUES(1,'哈哈',100,1);
ROLLBACK;
#3.创建视图,实现查询价格大于100的书名和类型名
CREATE VIEW myv1
AS
SELECT bname,NAME
FROM book b
JOIN bookType t ON b.btypeid=t.id
WHERE price>100;
#4.修改视图,实现查询价格在90-120的书名和价格
CREATE OR REPLACE VIEW myv1
AS
SELECT bname,price
FROM book
WHERE price BETWEEN 90 AND 120;
#5删除刚刚创建的视图
DROP VIEW myv1;
测试题讲解---mysql
最新推荐文章于 2024-10-30 22:57:10 发布