sql查看视图字段信息_高级(视图 索引)
生活随笔
收集整理的這篇文章主要介紹了
sql查看视图字段信息_高级(视图 索引)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
-- 視圖-- -- 視圖可以隱藏真正的表結構,對于比較重要的數(shù)據(jù)(如銀行),只讓別人訪問視圖,沒有權限使用真正的表 --?創(chuàng)建視圖 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、右邊客戶端:開啟事務,插入數(shù)據(jù)begin;insert into students(studentNo,name) values ('013','abc');3、右邊客戶端:查詢數(shù)據(jù),此時有新增的數(shù)據(jù)select * from students;4、左邊客戶端:查詢數(shù)據(jù),發(fā)現(xiàn)并沒有新增的數(shù)據(jù)select * from students;5、右邊客戶端:完成提交commit;?6、左邊客戶端:查詢,發(fā)現(xiàn)有新增的數(shù)據(jù)select * from students;回滾rollback 兩個命令行客戶端 左邊客戶端 右邊客戶端1、左邊客戶端:查詢學生信息select * from students;2、右邊客戶端:開啟事務,插入數(shù)據(jù)begin;insert into students(studentNo,name) values ('014','aaa');3、右邊客戶端:查詢數(shù)據(jù),此時有新增的數(shù)據(jù)select * from students;4、左邊客戶端:查詢數(shù)據(jù),發(fā)現(xiàn)并沒有新增的數(shù)據(jù)select * from students;5、右邊客戶端:回滾rollback;6、左邊客戶端:查詢,發(fā)現(xiàn)沒有新增的數(shù)據(jù) |
--索引--
show index from 表名;
create table create_index( id int primary key, name varchar(10) unique, age int, key (age) ); (創(chuàng)建表時,對于主鍵和unique字段,自動創(chuàng)建索引) 方式二:對于已經(jīng)存在的表,添加索引如果指定字段是字符串,需要指定長度,建議長度與定義字段時的長度一致 字段類型如果不是字符串,可以不填寫長度部分 create index 索引名稱 on 表名(字段名稱(長度)) 例: create index age_index on create_index(age); create index name_index on create_index(name(10));
實操: 創(chuàng)建測試表testindexcreate table test_index(title varchar(10));創(chuàng)建存儲過程create procedure proc_test()在navicat查詢中,執(zhí)行下面sql語句;(創(chuàng)建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?調(diào)用存儲過程,向表中添加數(shù)據(jù)call proc_test()?開啟運行時間監(jiān)測:set profiling=1;查找第1萬條數(shù)據(jù)test10000select * from test_index where ;查看執(zhí)行的時間:show profiles;結果:時間長;為表title_index的title列創(chuàng)建索引:create index title_indexontest_index(title(10));執(zhí)行查詢語句:select * from test_index where ;再次查看執(zhí)行的時間show profiles;結果:時間短;(索引的作用) |
總結
以上是生活随笔為你收集整理的sql查看视图字段信息_高级(视图 索引)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: P2249 【深基13.例1】查找(AC
- 下一篇: python做炫酷的界面_用python