網(wǎng)站首頁 編程語言 正文
一、序列
序列可以使用在數(shù)據(jù)庫表的自動增長列中來用,假如我們的學生表的id想從1開始,然后自動增長,每次增加2,也就是學生id是1、3、5、7、9這種的,我們就可以配合序列來使用
序列有以下屬性
sequence_name:序列名稱
min_value:當前序列的最小值
max_value:當前序列的最大值
increment_by:每次序列增長的步長
cy:是否為循環(huán)序列
or:是否需要排序
cache_size:緩存?zhèn)€數(shù),默認為20個
last_number:最后的數(shù)值
nextval:取得序列下一個內(nèi)容,每調(diào)用一次序列的值都會增長
currval:表示取得序列的當前內(nèi)容,每一次調(diào)用序列不會增長
1、創(chuàng)建一個序列
create sequence myseq;
2、向?qū)W生表插入一條數(shù)據(jù),學生id使用myseq序列
insert into student(id,name) values (myseq.nextval;'張三');
3、改變myseq序列的步長,每步增加2
create sequence myseq increment by 2;
4、改變myseq序列的開始值為10000
create sequence myseq increment by 2 start with 10000;
5、創(chuàng)建一個循環(huán)序列,并且不使用緩存
如果我們希望某一列的數(shù)據(jù)只是1到9的數(shù)據(jù),那么我們可以使用循環(huán)序列來操作
create sequence myseq
minvalue 1 maxvalue 9
cycle nocache;
二、同義詞的作用
同義詞可以將一個模式的表給另一個模式來訪問。
1、將scott用戶下的student表同義給sys用戶使用
create sysnoym student for scott.emp;
2、將scott用戶下的student表同義給所有用戶使用
create public sysnoym student for scott.emp;
三、視圖的定義及使用
視圖是為了簡化復雜查詢的,視圖是一張?zhí)摂M表,并不存儲數(shù)據(jù),但是數(shù)據(jù)都來源于真實表中
1、創(chuàng)建一個視圖,從學生表中名字為‘張三’的學生中取
create view studentview as select * from student where name = '張三';
2、查詢學生視圖
select * from studentview;
3、更新學生視圖,將name為‘張三’的年齡更新為20
update studentview set age = 20 where name = '張三';
這個時候我們發(fā)現(xiàn)真實表student中張三的年齡也被修改了,所以這樣修改視圖會影響真實表的數(shù)據(jù),那么我們接下來創(chuàng)建一個視圖讓他修改后不影響真實表。
4、創(chuàng)建一個視圖,從學生表中名字為‘張三’的學生中取,并且修改視圖不能影響原來真實表的數(shù)據(jù)
create or replace view studentview as
select * from student where name = '張三'
with check option;
5、創(chuàng)建一個視圖,從學生表中名字為‘張三’的學生中取,并且視圖設置為只讀
create or replace view studentview as
select * from student where name = '張三'
with read only;
四、索引的定義及使用
1、創(chuàng)建一個學生表,并給name建立索引
create index name_index on student (name);
五、總結(jié)
這里的相關內(nèi)容還沒有整理完畢,文章后面持續(xù)更新,建議收藏。
文章中涉及到的命令大家一定要像我一樣每個都敲幾遍,只有在敲的過程中才能發(fā)現(xiàn)自己對命令是否真正的掌握了。
原文鏈接:https://blog.csdn.net/weixin_44096133/article/details/125547169
相關推薦
- 2022-12-05 Android實現(xiàn)自動變換大小的ViewPager_Android
- 2023-05-24 pytorch中retain_graph==True的作用說明_python
- 2022-07-13 IO流詳解之字符流與File類
- 2022-07-13 SpringBoot中的SmartInitializingSingleton接口的使用
- 2022-04-30 python的正則表達式和re模塊詳解_python
- 2022-05-12 Android 11 適配存儲權(quán)限
- 2022-07-11 BeanDefinition的作用 及 new ApplicationContext容器的加載過程
- 2023-02-02 C語言如何實現(xiàn)三子棋_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支