147测试题

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,    #约束条件unique和not null没有顺序要求
price float default 10,
#    btypeId int references bookType(id)    可以这么写,但是没效果
btypeId int,
foreign key(btypeId) references bookType(id)
);


2、开启事务
向表中插入1行数据,并结束
set autocommit=0insert into book (bid,bname,price,btypeId)
values (1,'小李飞刀',100,1);

rollback;或者commit;

3、创建视图,实现查询价格大于100的书名和类型名
create view myv1
as
select bname,btypeId
from book b
inner join bookType t on b.btypeid=t.id
where price > 100;

4.修改试图,实现查询价格在90-120之间的书名和价格
create or replace myv1
as
select bname,price
from book
where price between 90 and 120;

5.删除刚建的视图
drop from myv1;
原文地址:https://www.cnblogs.com/tan-y-q/p/10624205.html