视图
-- 创建视图
create view v_student AS
select name 姓名,age 年龄 from student;
-- 查询视图
select * from v_student;
结果:
姓名 年龄
诸葛亮 20
甄宓 18
事务
手动执行事务(一步一步执行,正常最后执行commit,遇到异常执行rollback;
-- 正常情况
begin;
update account set account=account-100 where name='大乔';
update account set account=account+100 where name='小乔';
commit;
-- 另一种写法
start transaction;
update account set account=account-100 where name='大乔';
update account set account=account+100 where name='小乔';
commit;
select * from account;
-- 异常情况(账户余额不能为负数)
begin;
update account set account=account-100 where name='大乔';
update account set account=account+100 where name='小乔';
-- insert 语句 into可以省略
insert account(name,account) VALUES('孙尚香',-1000);
ROLLBACK;