-- 视图-- -- 视图可以隐藏真正的表结构,对于比较重要的数据(如银行),只让别人访问视图,没有权限使用真正的表 -- 创建视图 create view v_stu_score_course asselect stu.name,stu.class,sc.score,cs.name as a from students stuINNER JOIN scores sc on stu.studentNo=sc.studentNoINNER JOIN courses cs on cs.courseNo=sc.courseNo-- 使用视图 select * from v_stu_score_course |
--事务-- 提交commit; 两个命令行客户端 左边客户端 右边客户端 1、左边客户端:查询学生信息select * from students;2、右边客户端:开启事务,插入数据begin;insert into students(studentNo,name) values ('013','abc');3、右边客户端:查询数据,此时有新增的数据select * from students;4、左边客户端:查询数据,发现并没有新增的数据select * from students;5、右边客户端:完成提交commit; 6、左边客户端:查询,发现有新增的数据select * from students;回滚rollback 两个命令行客户端 左边客户端 右边客户端1、左边客户端:查询学生信息select * from students;2、右边客户端:开启事务,插入数据begin;insert into students(studentNo,name) values ('014','aaa');3、右边客户端:查询数据,此时有新增的数据select * from students;4、左边客户端:查询数据,发现并没有新增的数据select * from students;5、右边客户端:回滚rollback;6、左边客户端:查询,发现没有新增的数据 |
--索引--
方式二:对于已经存在的表,添加索引
实操: 创建测试表testindexcreate table test_index(title varchar(10));创建存储过程create procedure proc_test()在navicat查询中,执行下面sql语句;(创建test_index表,并添加100000条记录,命名为title(i))begindeclare i int default 0;while i<100000 doinsert into test_index(title) values(concat('test',i));set i=i+1;end while;end 调用存储过程,向表中添加数据call proc_test() 开启运行时间监测:set profiling=1;查找第1万条数据test10000select * from test_index where ;查看执行的时间:show profiles;结果:时间长;为表title_index的title列创建索引:create index title_indexontest_index(title(10));执行查询语句:select * from test_index where ;再次查看执行的时间show profiles;结果:时间短;(索引的作用) |
sql查看视图字段信息_高级(视图 索引)
最新推荐文章于 2024-04-18 09:06:40 发布